Tuesday, June 26, 2012

Remove all non-alphanumeric characters from a string

In C#:
Regex rgx = new Regex("[^a-zA-Z0-9 -]");
str = rgx.Replace(str, "");
 
This replaces all non-alphanumeric characters with the empty string (""). You can replace 
the "" part with whatever character you wish to replace it with.
 
Reference:
1. Stack Overflow
 

No comments:

Post a Comment

There was an error in this gadget