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

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

福建师范大学协和学院-本科-信息管理和信息系统-2011年6月毕业-4年工作经验-女-26岁

 for(String keyStr:keyword.split(":")){
      Matcher slashMatcher = Pattern.compile("-").matcher(keyStr);
         int mIdx = 0;
         String[] keyArr=keyStr.split("-");
         while(slashMatcher.find()) {
            mIdx++;
            //当"-"符号第四次出现的位置
            if(mIdx == 4){
             jobExe=keyArr[4];
            }else if(mIdx == 5){
             sex=keyArr[5];
            }else if(mIdx == 6){
             age=keyArr[6];
            }
           
         }
     }

原文地址:https://www.cnblogs.com/beijingstruggle/p/4910730.html