</pre><pre name="code" class="java"><pre name="code" class="java"> /**
*
* @param str ----原有自动
* @param sub----出现字段
* @return
*/
public static int getCharCount ( String str , String sub){
if ( isEmpty( str ) || isEmpty( sub ) ){
return 0;
}
int times = 0 ;
int minlength = sub.length();
for( int i=0;i<str.length()-1 ;) {
String tempSub=str.substring(i, i+minlength );
if(tempSub.equals( sub)){
times++;
i = i+minlength ;
continue ;
}
i++;
}
return times ;
}
字符串a在字符串b中出现次数
最新推荐文章于 2022-03-15 20:23:35 发布