日期:2014-05-18  浏览次数:20701 次

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


------解决方案--------------------
IndexOf 函数。
------解决方案--------------------
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());
}

不知道你是不是这个意思。。