例如
string1="a=2,b=3,c=4,"
string2="a=4,b=2,c=9,"
比较结果是"a=[不同1],b=[不同2],c=[不同3]," ?

解决方案 »

  1.   

    没有直接的方法吧,应该先对
    string1,string2用split拆分,再比较
      

  2.   

      string string1 = "a=2,b=3,c=4,";
                string str = string1;
                int i = 0;
                var list = Regex.Matches("a=4,b=2,c=9,", @"(?i)(?<=,|^)([a-z]+=)(\d+)(,|$)").OfType<Match>().Select(t => new { txt = t.Value, left = t.Groups[1].Value }).ToList();
                str = Regex.Replace(str, @"(?i)(?<=,|^)([a-z]+=)(\d+)(,|$)", delegate(Match m)
                {
                    string left = m.Groups[1].Value;
                    if (list.Count(t => t.left == left) < 1)
                        return left + "[不包含]" + m.Groups[3].Value;
                    return m.Groups[1].Value + (list.Count(t => t.txt == m.Value) > 0 ? "[相同]" : string.Format("[不同{0}]", ++i)) + m.Groups[3].Value;
                });
                Console.WriteLine(str);
      

  3.   

    可以用linq,写个自定义比较器
      

  4.   

     static void Main(string[] args)
            {
                string temA = "a=1,b=2,c=3,d=4,e=5";
                string temB = "a=1,b=4,c=3,d=4,e=10";            string[] a = temA.Split('=', ',');
                string[] b = temB.Split('=', ',');
                string line = "";            for (int i = 1, j = 0, k = 0; i < a.Length; i++)
                {
                    if (a[i] == b[i])
                    {
                        j++;
                        line = line + a[i - 1] + "=" + "相等" + j + " ";
                    }
                    else
                    {
                        k++;
                        line = line + a[i - 1] + "=" + "不想等" + k + " ";
                    }
                    i++;
                }            Console.WriteLine(line);
                Console.ReadLine();
            }