public static int ContainCount(string input, string findstr, bool ignoreCase)
{
if (ignoreCase)
{
input = input.ToLower();
findstr = findstr.ToLower();
}
int count = 0;
for (int i = 0; (i = input.IndexOf(findstr, i)) >= 0; i=i+findstr.Length)
{
count++;
}
return count;
}
字符串匹配计数方法
本文介绍了一种在字符串中查找特定子串出现次数的方法,并可根据需求进行大小写忽略设置。该方法通过遍历输入字符串并使用IndexOf方法定位目标子串的位置来实现计数。
1094





