strReason中存放了如下字符串:  BR_1310-75;BR_1310-85;Po@Ith+20mA-25;Slope-25;Vf@Ith+20mA-25;Ith-25我想检查strReason中是否存在"Po@Ith+20mA-25",程序如下:Regex r = new Regex("Po@Ith+20mA-" + TestTemp.Text);
if(r.IsMatch(strReason) == false)
  strReason += ";Po@Ith+20mA-" + TestTemp.Text;其中TestTemp中存放的是温度,可是IsMatch方法返回的结果总是False,不知为什么?

解决方案 »

  1.   

    string strReason = "BR_1310-75;BR_1310-85;Po@Ith+20mA-25;Slope-25;Vf@Ith+20mA-25;Ith-25";
    System.Text.RegularExpressions.Regex  r = new System.Text.RegularExpressions.Regex("Po@Ith[+]20mA-");
    bool tmp = r.IsMatch(strReason);//结果为true
      

  2.   

    我改为Regex r = new Regex("[Po@Ith+20mA-" + TestTemp.Text + "]");提示错误。怎么改呢?
      

  3.   

    其实,这个问题完全没有必要用正则,用正则反而麻烦,这样写就可以了:if(strReason.IndexOf("Po@Ith+20mA-" + TestTemp.Text)>-1)
      strReason += ";Po@Ith+20mA-" + TestTemp.Text;
      

  4.   

    啊, 好好 。谢谢~~
    Contains方法似乎是StringCollection的方法