判断String大串中包含多少个小串
程序员文章站
2022-06-17 14:54:52
...
String maxString = "Write2Db.jarWrite2Db.jarWrite2Db.jar;
String minString="Write2Db.jar";
int count=getCount(maxString, minString);
public static int getCount(String maxString, String minString) {
// 定义一个统计变量,初始化值是0
int count = 0;
int index;
//先查,赋值,判断
while((index=maxString.indexOf(minString))!=-1){
count++;
maxString = maxString.substring(index + minString.length());
}
return count;
}
上一篇: 求1-100中有多少个9
下一篇: VBS打开当前脚本所在文件夹