简单的字符串处理!C#

来源:百度知道 编辑:UC知道 时间:2024/04/27 22:42:27
string QuestionUrl = "dsgsdaztx008fdghdfhaztx008";

输出aztx008这组字符出现的次数???

应该是输出2次的阿!

string QuestionUrl = "dsgsdaztx008fdghdfhaztx008";
System.Text.RegularExpressions.MatchCollection m = System.Text.RegularExpressions.Regex.Matches(QuestionUrl, "aztx008");
MessageBox.Show(m.Count.ToString());

看看行不行
public static int GetStringCount(string sourceString,string findString)
{
int count = 0;
int findStringLength = findString.Length;
string subString = sourceString;

while(subString.IndexOf(findString)>=0)
{
subString = subString.Substring(subString.IndexOf(findString)+findStringLength);
count += 1;
}
return count;
}