Friday, January 30, 2009

C# : Removing non-ASCII characters

I was trying to filter some files and remove all the non-ASCII characters. Using Mr. Google lead me to this very helpful
post.

Essentially:


string s = "søme string";
s = Regex.Replace(s, @"[^\u0000-\u007F]", "");


I didn't want control characters so my filter was \u0020-\u007F.

Enjoy!