Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# replace characters in string that are invalid using regex

string pattern = "[~#%&*{}/:<>?|"-]";
string replacement = " ";

Regex regEx = new Regex(pattern);
string sanitized = Regex.Replace(regEx.Replace(input, replacement), @"s+", " ");

This will replace runs of whitespace with a single space as well.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #replace #characters #string #invalid #regex
ADD COMMENT
Topic
Name
9+6 =