Splistr是接收过来的字符串:“101,102,105,106”
if (splistr != null)
        {
            DataSet ds_hwbh =sqlhelper.GetDataSet("select hwbh from fhxx where fhqdh='"+fhqdh_edit+"'");//这个是原来fhxx中保存的hwbh
      Ds_hwbh已经转为字符串tmp:"101,102,103,104"
103,104是原来已经保存过的编号,状态已经改变了,现在要在删除之前将其状态恢复为01
105,106是新增加的编号不管其状态。
现在如何通过对比splistr和tmp两字符串,得出103,104这两个编号,将他们的状态update为01

解决方案 »

  1.   

    string s1 = "101,102,105,106";
    string s2 = "101,102,103,104";
    string[] s3 = Regex.Split(s2, @"[,,\s]+").Except(Regex.Split(s1, @"[,,\s]+")).ToArray();s3就是你要的结果
      

  2.   

    System.array不包含except 的定义,并且找不到可接受类型为system .array的第一个参数的扩展方法except 
      

  3.   

    .net framework3.0/3.5使用Linq
    或是
    .net framework2.0使用LinqBrige.dll
    添加
    using System.Linq;
      

  4.   

    string s1 = "101,102,105,106";
    string s2 = "101,102,103,104";

    MatchCollection matches = Regex.Matches(s1, "\b" + s2.Replace(',','|') + "\b", RegexOptions.None);
    foreach(Match match in matches)
    {
    //match.Value; //这就是你要的id
    }
      

  5.   


    不行啊 matches的couts总是为0
      

  6.   


    不行啊 matches的count总是为0