user135498 user135498 - 1 year ago 163
C# Question

C# Ensure string contains only ASCII

I have a C# routine that imports data from a csv file, matches it against a database and then rewrites it to a file. The source file seems to have a few non-ascii characters that are fouling up the processing routine.

I already have a static method that I run each input field through but it performs basic checks like removing commas and quotes. Does anybody know how I could add functionality that removes non-ascii characters too?


Answer Source
string sOut = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(s))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download