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];
            }
           
         }
     }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM