public class Test02 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入字符串");
String scrStr = scanner.nextLine();
System.out.println("请输入需要删除的字符串");
String delStr = scanner.nextLine();
int count = 0;
while (scrStr.contains(delStr)) {
scrStr = scrStr.replaceFirst("java", "").trim();
scrStr = scrStr.replace(" ", " ");
count++;
}
System.out.println("源字符串中总共包含: " + count + " 个 " + delStr + " 删除" + delStr + "后的字符串为: " + scrStr);
}
}
删除该字scrStr符串中的所有delStr字符串
最新推荐文章于 2022-06-12 13:30:08 发布