<strong>有时候我们需要在一个长字符串中匹配我们需要的字符,这里我就写了一个方法,用来统计,我们要匹配的字符在长字符串中出现的次数</strong>
/**
* 计算一个字符串中包含另一个字符串的个数
* @param @param str1
* @param @param str2
* @return int
* @author Mr_Cheng
* @date 2015-9-11
*/
public static int countStr(String one, String two){
int counter=0;
if (one.indexOf(two) == -1) {
return 0;
}
while(one.indexOf(two)!=-1){
counter++;
one=one.substring(one.indexOf(two)+two.length());
}
return counter;
}