首页 > 编程语言 > 详细

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

时间:2015-10-26 13:35:48      阅读:368      评论:0      收藏:0      [点我收藏+]

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

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

原文:http://www.cnblogs.com/beijingstruggle/p/4910730.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!