Java 获取字符串中第N次出现的字符位置

public static int getCharacterPosition(String string){
	    
	    Matcher slashMatcher = Pattern.compile("/").matcher(string);
	    int mIdx = 0;
	    while(slashMatcher.find()) {
	       mIdx++;
	       //当"/"符号第二次出现的位置
	       if(mIdx == 2){
	          break;
	       }
	    }
	    return slashMatcher.start();
	}

你可能感兴趣的:(Java 获取字符串中第N次出现的字符位置)