日期:2014-05-17  浏览次数:20861 次

请问如何过滤字符串里面非中文特殊字符?
 例如用 
 string theStr="";
 theStr= textBox1.Text; //textBox1 里面的字符正常应该是中文,但有可能包含一些特殊字符,例如一些看不到的换行符又或者一些特殊的标记
 
 假设 theStr 正常的数值应该是“张三”, 如果不过滤,直接把theStr插入到数据库会显示 "张三 ?传"  、 "张三 ??" 或 "张三 ?钞" 等。

------解决方案--------------------

class Class1 

static void Main() 

string s = "中文 chinese"; 
Regex regx = new Regex("[\u4e00-\u9fa5]+"); 
Match m = regx.Match(s); 
Console.WriteLine(m.Groups[0].Value); // 中文 
Console.ReadKey(); 




楼主可以参考一下这个用法