/**
* 計算某個字符子串在字符串中出現的次數
* @param str1 完整的字符串
* @param str2要計數的字符串片段
* @return
*/
public static int countStr(String str1,String str2){
int count = 0;
int start = 0;
while (str1.indexOf(str2, start) >= 0 && start < str1.length()) {
count++;
start = str1.indexOf(str2, start) + str2.length();
}
return count;
}
计算字符串中字符子串的出现次数
最新推荐文章于 2022-01-13 19:42:20 发布