zoukankan      html  css  js  c++  java
  • 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];
                }
               
             }
         }

  • 相关阅读:
    剑指Offer
    剑指Offer
    剑指Offer
    选书
    马的遍历
    从事效应
    魔性的素数环1~20 自带解释~
    [POJ1236]Network of Schools(并查集+floyd,伪强连通分量)
    [HDOJ3974]Assign the task(建树胡搞)
    [HDOJ4027]Can you answer these queries?(线段树,特殊成段更新,成段查询)
  • 原文地址:https://www.cnblogs.com/beijingstruggle/p/4910730.html
Copyright © 2011-2022 走看看