public class DemoText {
public static void main(String[] args) {
fun1();
}
public static void fun1(){
String s = "hello word Ok Yes hello hello";
int sum=0;
while(s.contains("lo")){
sum++;
s=s.replaceFirst("lo", "");
}
System.out.println("指定字符串在原字符中出現:"+sum+"次");
}
}