从字符串中删除所有非ASCII字符 [英] Remove all non-ASCII characters from string

查看:158
本文介绍了从字符串中删除所有非ASCII字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#例程,该例程从CSV文件导入数据,将其与数据库进行匹配,然后将其重写为文件.源文件似乎包含一些非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.

我已经有一个静态方法,可以运行每个输入字段,但是它执行基本的检查,例如删除逗号和引号.有人知道我如何添加也可以删除非ASCII字符的功能吗?

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?

推荐答案

string sOut = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(s))

这篇关于从字符串中删除所有非ASCII字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆