Saturday 1 April 2017

c# - How do I remove all non alphanumeric characters from a string except dash?




How do I remove all non alphanumeric characters from a string except dash and space characters?


Answer



Replace [^a-zA-Z0-9 -] with an empty string.



Regex rgx = new Regex("[^a-zA-Z0-9 -]");
str = rgx.Replace(str, "");

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...