public class Demo {
public static void main(String[] args) {
String s = "woaijavahahajavaaiwo";
String ss = "java";
StringBuilder sb = new StringBuilder(s);
int count = 0;
for (int i = 1; i <= s.length(); i++) {
int x = sb.indexOf(ss);
if (x != -1) {
count++;
sb.delete(x, x + ss.length());
}
}
if (count != 0) {
System.out.println("删除字符串java " + count + "次\n" + "目前字符串为"
+ sb.toString());
}else{ System.out.println("你输入的长串不含小串");
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |