/**
* 计算一个字符串中包含某个子字符串的个数
* @author lin
* @param sourcestr 要检测的字符串
* @param findstr 要查找的子字符串
*/
public int substringCount(String sourcestr,String findstr)
{
int counter = 0;
int startposition = 0;
while(startposition < sourcestr.length()){
int search = sourcestr.indexOf(findstr, startposition);
if(search != -1){
counter++;
startposition = search + findstr.length();
}else{
break;
}
}
return counter;
}
计算一个字符串中包含某个字符串的个数
最新推荐文章于 2022-05-03 10:56:04 发布