public class findStrNum {
public static void main(String[] args) {
String str = "a abc fo abc gsdfsdsbcsgsod abcsgs abc";
int fromIndex = 0;
int count = 0;
while(true){
int index = str.indexOf("abc", fromIndex);
if(-1 != index){
fromIndex = index + 1;
count++;
}else{
break;
}
}
System.out.println(count);
}
}
Java实现获取指定字符串中某个子字符串出现的个数
最新推荐文章于 2025-03-04 08:56:06 发布