现在又两条字符串,我需要把所有位置匹配的字符求出来,请问各位大神,该怎么做?例如两条字符串分别为string s1=abcd,string s2=dabd,那么我需要把下面的都匹配,得到字符匹配最多的个数。
***abcd **abcd *abcd abcd abcd* abcd** abcd***  
dabd*** dabd** dabd* dabd *dabd **dabd ***dabd
字符串长度大概在20个字符之间

解决方案 »

  1.   

    static void Main(string[] args)
            {
                string s1 = "abcd";
                string s2 = "dabd";
                string s3 = "***abcd **abcd *abcd abcd abcd* abcd** abcd***   dabd*** dabd** dabd* dabd *dabd **dabd ***dabd";            string[] splits1 = s3.Split(new string[] { s1 }, StringSplitOptions.RemoveEmptyEntries);
                string[] splits2 = s3.Split(new string[] { s2 }, StringSplitOptions.RemoveEmptyEntries);            Console.WriteLine(splits1.Count());
                Console.WriteLine(splits2.Count());
            }不知道你是不是这个意思。。
      

  2.   

    c# 菜鸟,不太懂你的意思。 我的意思是从两个字符串中找出能够匹配的相同字符的个数。像这个例子里最多只会有二个字符匹配
    *abcd
    dabd*
    就是这种情况