String str = "|1||2||124|";
String subStr = "||";
int count = 0;
int index = 0;
while ((index = str.indexOf(subStr, index)) != -1) {
System.out.print("位置:"+index+" ");
count++;
index += subStr.length();
}
System.out.println(count);
统计字符串中子串出现的次数与位置
最新推荐文章于 2022-07-07 20:59:28 发布