I am looking to take a string from an input text box and remove all special characters and spaces.
e.g.
Input: ##HH 4444 5656 3333 2AB##
Output: HH4444565633332AB
I am looking to take a string from an input text box and remove all special characters and spaces.
e.g.
Input: ##HH 4444 5656 3333 2AB##
Output: HH4444565633332AB
2
Answers
Let’s define what we are going to keep, not what to remove. If we keep Latin letters and digits only we can put
or (Linq alternative)
If dealing with unicode to remove one or more characters that is not a letter nor a number:
See this demo at regexstorm or a C# replace demo at tio.run
p{L}
matches any kind of letter from any languagep{N}
matches any kind of numeric character in any script