/*** * 计算字符串在某串中出现的次数 * @param source 某串 * @param word 计算次数的字符 * @return */ public static int getWordCount(String source, String word) { int count = 0; int start; while ((start = source.indexOf(word)) != -1) { count++; source = source.substring(start + word.length()); } return count; }