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);
}
}
stringBuilder统计字符串中子字符个数
最新推荐文章于 2024-09-04 02:27:36 发布