Remove all non-ASCII characters from string

后端 未结 7 1169
野的像风
野的像风 2020-12-05 06:28

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

7条回答
  •  余生分开走
    2020-12-05 06:55

    If you wanted to test a specific character, you could use

    if ((int)myChar <= 127)
    

    Just getting the ASCII encoding of the string will not tell you that a specific character was non-ASCII to begin with (if you care about that). See MSDN.

提交回复
热议问题