日期:2014-05-18  浏览次数:20484 次

菜鸟求助,Regex.IsMatch正则表达式不认中文的问题
很奇怪的问题,我这样写
C# code
string[] sentences = 
  {
   "你",
   "x"
   };
 bool find = false;
 string sPattern = this.content.Text;
 foreach (string s in sentences)
    {
    if (System.Text.RegularExpressions.Regex.IsMatch(sPattern,s))
    {
    //找到了
    }
    else
    {
    //没有找到
    }

然后我在content里提交“你”,他能够识别出来,但是如果我用下面的方法
C# code
FileStream fs = new FileStream(Server.MapPath(".")+"\\test1.txt",FileMode.Open,FileAccess.Read); 
    StreamReader sr = new StreamReader(fs); 
    string[] words= sr.ReadToEnd().Split('|'); 
 bool find = false;
 string sPattern = this.content.Text;
 foreach (string s in words)
    {
    if (System.Text.RegularExpressions.Regex.IsMatch(sPattern,s))
    {
    //找到了
    }
    else
    {
    //没有找到
    }

test1.txt里面的内容为 你|x
但是问题出现了,我无论提交什么中文他都是别不了,但是英文却是可以。。。
请问是怎么回事?

------解决方案--------------------
那我接分,呵呵
------解决方案--------------------
你IsMatch的两个参数弄反了吧