//计算字符串str中某字串substring出现的次数
int countNumOfSubstringInString(string substring,string str)
{
int startIndex=-1;
int endStartIndex = -1;
int num=0;
int countNumOfSubstringInString(string substring,string str)
{
int startIndex=-1;
int endStartIndex = -1;
int num=0;
endStartIndex = str.find(substring);
while (endStartIndex!=string::npos)
{
num++;
startIndex = endStartIndex + substring.length();
endStartIndex = str.find(substring,startIndex);
}
return num;
while (endStartIndex!=string::npos)
{
num++;
startIndex = endStartIndex + substring.length();
endStartIndex = str.find(substring,startIndex);
}
return num;
}
转载于:https://blog.51cto.com/pingpeace/223240