字符串出现的次数
2019-02-19 本文已影响0人
一起走天下
public static int getCount(String str,String sq){
int idx = 0;
int count = 0;
while ((idx = str.indexOf(sq,idx))!=-1){
count++;
idx += sq.length();
}
return count;
}
public static int getCount(String str,String sq){
int idx = 0;
int count = 0;
while ((idx = str.indexOf(sq,idx))!=-1){
count++;
idx += sq.length();
}
return count;
}