计算字符串中子字符串出现的次数

    科技2025-07-10  15

    String str = "ccc"; String subStr = "cc"; int strLength = str.length(); int subStrLength = subStr.length(); int count = 0; int index = str.indexOf(subStr); while (index != -1) { count++; index = str.indexOf(subStr, index + subStrLength); } System.out.println(count);

    若有疑问,欢迎留言 ^ _ ^

    Processed: 0.016, SQL: 9