package day12;
public class TextString5 {
public static void main(String[] args) {
Count();
}
public static void Count() {
String s1 = "abcdefabc123ab";
String s2 = "ab";
int count=0;
for (int i= 0; s1.indexOf(s2) != -1; i++) {
count++;
s1 = s1.substring(s1.indexOf(s2) + 2);
}
System.out.println(count);
}
}
判断一个字符串里面的子串出现的次数
最新推荐文章于 2023-02-10 14:16:38 发布