首页 > 编程 > Java > 正文

java获取某个子字符串在整个字符串中第N次出现时的下标索引

2019-11-11 02:39:28
字体:
来源:转载
供稿:网友
PRivate int getFromIndex(String str,Integer count) {	Matcher slashMatcher = Pattern.compile("test").matcher(str);	int index = 0;        //matcher.find();尝试查找与该模式匹配的输入序列的下一个子序列       while(slashMatcher.find()) {	    index++;	    //当"test"符号第四次出现的位置	    if(index == count){	       break;	    }	}        //matcher.start();返回以前匹配的初始索引。       return slashMatcher.start();}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表