比方说我现在
 string b=@"1|2|3|4|5|6|7|8|9|10|11|12|13|14|20|21";
 string a="1"; b.LastIndexOf(a);
或者
 b.IndexOf(a);
 
 我要让他找到1但不会找到11/12/13/14/21等处。而查找11时就只会找到11。总之是查找得不准确!

解决方案 »

  1.   

    string[] arrList = b.Split("|");foreach(string str in arrList)
    {
       if(str == a)
          break;
    }我的笨办法,嘿嘿
      

  2.   

    using System.Text.RegularExpressions;
    ...
    MatchCollection mc = Regex.Matches(b, "\\b" + a + "\\b");
    foreach(Match m in mc)
         Console.WriteLine(m.Value);
      

  3.   

    另外一个方法string b=@"1|2|3|4|5|6|7|8|9|10|11|12|13|14|20|21";
     string a="1";a="|"+a+"|";
    b="|"+b+"|";再使用 b.LastIndexOf(a);
    或者
     b.IndexOf(a);
      

  4.   

    senkiner(金龍) 的方法不是太理解.websol(歪脖树) 的方法可以使用但只局限于这种行式下用.
      

  5.   

    下面是一个分割和比较的例子。希望对你有用:
    private void Button1_Click(object sender, System.EventArgs e)
    {
      string tmpstr = this.TextBox1.Text.ToString();
      if(!RegFilter(tmpstr))
      {
        Dostring.ShowMessageBox("ok",this.Page);
      }
      else
      {
        Dostring.ShowMessageBox("no",this.Page);
      }
    }public bool RegFilter(string str)
    {
      string tmpStr = str.Trim().ToLower();
      if(tmpStr.Length < 0)
      {
        return false;
      }
    string split = "|exec|insert|select|delete|update|count|*||'|master|truncate|char|declare|xp_|sp_|Union";
      string[] tmpSplit = split.Split('|');
      for(int i=0; i<tmpSplit.Length-1; i++)
      {
         if(tmpStr.IndexOf(tmpSplit[i]) > 0)
         {
            return false;
         }
      }
         return true;
    }