java 计算指定字符串中目标字符串出现的次数
public static void findCount(String src, String des) { int index = 0; int count = 0; while ((index = src.indexOf(des, index)) != -1) { count++; index = index + des.length(); } System.out.println(des + "出现了 " + count + " 次"); }
src指定字符串 des目标字符串