统计字符串中子串出现的次数与位置

来源:互联网 发布:网络拍卖经营许可证 编辑:程序博客网 时间:2024/06/10 10:06
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);

原创粉丝点击