请问如何能判断两个符字串的单个字符和字符个数相符,例如"ABC"和"CAB"相比较的话应该返回true,而"ABC"和"AC"比较的话就返回false

解决方案 »

  1.   

    可以先判断长度是否相等,然后Sort()后==
      

  2.   

    Sort()可以吗?能否举个简单的例子?谢了
      

  3.   


                Console.WriteLine("input string1:");
                string str1 = Console.ReadLine();
                Console.WriteLine("input string2");
                string str2 = Console.ReadLine();
                int count = 0;
                string resultstr = string.Empty;
                if (str1.Length == str2.Length)
                {
                     foreach(char c in str1)
                    {
                        if (str2.Contains(c))
                            count++;
                    }                 if (count == str2.Length)
                         resultstr = "TRUE";
                     else
                         resultstr = "FALSE";
                }
                else
                    resultstr = "FALSE";
                Console.WriteLine(resultstr);            Console.ReadKey();
      

  4.   

    string s1 = "ABC";
    string s2 = "CAB";
    char[] c1 = s1.ToCharArray();
    char[] c2 = s2.ToCharArray();
    Array.Sort(c1);
    Array.Sort(c2);
    Response.Write(new string(c1) == new string(c2));
    true
      

  5.   


    照这个代码"BB"和"BC"比较返回的结果是错的