标签:while [] text int class color log blog compile
方法一
public int count(String srcText, String findText) { String[] array = srcText.split(findText); return array.length - 1; }
方法二
public static int count(String srcText, String findText) { int count = 0; Pattern p = Pattern.compile(findText); Matcher m = p.matcher(srcText); while (m.find()) { count++; } return count; }
方法三
public static int count(String srcText, String findText) { int count = 0; int index = 0; while ((index = srcText.indexOf(findText, index)) != -1) { index = index + findText.length(); count++; } return count; }
标签:while [] text int class color log blog compile
原文地址:http://www.cnblogs.com/zsg88/p/7599287.html