您的位置:首页 > 其它

在一个长字符串中判断存在几个另一个短字符串

2015-08-18 20:01 477 查看
public int getTimes(String str1, String str2) {
int count = 0;
int start;
while ((start = (str1.indexOf(str2))) >= 0) {
count++;
str1 = str1.substring(start + str2.length());
}
return count;
}
str1是长字符串,str2是短字符串。上面方法返回值即为长字符串中有几个短字符串。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: