获取母字符串中某个子字符串的某个确定的index值

该方法的作用,旨在:在longStr中找str,根据所传的theIndex来返回str在longStr中的第几个索引的字符串位置:

private int getIndexOfStrInLongStr(String longStr,String Str,int theIndex){
    Set indexInt = new LinkedHashSet<>();
    int indexStr = 0;
    int index = 0;
    if(StringUtils.isNotEmpty(longStr)){
        while (index != longStr.length()){
                indexStr = longStr.indexOf(Str,index);
                indexInt.add(indexStr);
            if(indexInt.size() < theIndex){
                index++;
            }else {
                break;
            }
        }
    }else {
        logger.error("本次需要获取的母字符串为空!");
    }

     return indexStr;
}

你可能感兴趣的:(Java)