匹配一个文件中的所有中文的正则表达式怎么写呀?
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=57728

解决方案 »

  1.   

    看内码就知道
    内码小于A0为英文ascii码,大于A0为中文。
    即:将输入转为byte,再域0xa0比较即可。
      

  2.   

    如何知道一个字符串里是否含有中文using System.Text.RegularExpressions; ...... bool yn=Regex.IsMatch(tex.Text,@"[\u4e00-\u9fa5]+");
    if(yn==true) 
    { MessageBox.Show("y"); //含有中文
    }
    else
    {
    MessageBox.Show("n"); //不含有中文
    }
    说明:@"[\u4e00-\u9fa5]+"的意思是查打汉字的位置。 
    \u4e00是第一个汉字的xx码。 \u9fa5是最后一个汉字的xx吗!
    如果你只是要匹配数字和英文字符可以用Matches ms = Regex.Matches(strline,@"^[^a-zA-Z0-9]+&");
    if(ms.Count != 1)
    {
    //error
    }
      

  3.   

    public bool IsChina(string CString)
    {
    bool BoolValue=false;
    for (int i =0 ;i<CString.Length ; i++)
    {
    if (Convert.ToInt32(Convert.ToChar(CString.Substring(i,1)))<Convert.ToInt32(Convert.ToChar(128)))
    {
    BoolValue = false;
    }
    else
    {
    BoolValue = true;
    }
    }
    return BoolValue;
    }