I have this statement:
String cap = Regex.Replace(winCaption, @"[^\w\.@-]", "");
that transforms "Hello | World!?" to "HelloWorld".
But I want to preserve space character, for example: "Hello | World!?" to "Hello World".
How can I do this?
just add a space to your set of characters, [^\w.@- ]
var winCaption = "Hello | World!?";
String cap = Regex.Replace(winCaption, @"[^\w\.@\- ]", "");
Note that you have to escape the 'dash' (-) character since it normally is used to denote a range of characters (for instance, [A-Za-z0-9])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With