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