C#确保字符串只包含ASCII [英] C# Ensure string contains only ASCII

查看:169
本文介绍了C#确保字符串只包含ASCII的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#程序,从一个CSV文件导入数据,它匹配对一个数据库,然后重写到文件中。源文件似乎已经被污染了处理程序的几个非ASCII字符。



我已经有一个我贯穿每个输入字段一个静态方法,但它执行等方法去除逗号和报价基本检查。有谁知道我怎么可以添加功能,太删除非ASCII字符?



谢谢,
克里斯


解决方案

 字符串SOUT = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(S))


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?

Thanks, Chris

解决方案

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

这篇关于C#确保字符串只包含ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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