獲取母字串中某個子字串的某個確定的index值
阿新 • • 發佈:2021-01-06
技術標籤:Java
該方法的作用,旨在:在longStr中找str,根據所傳的theIndex來返回str在longStr中的第幾個索引的字串位置:
private int getIndexOfStrInLongStr(String longStr,String Str,int theIndex){ Set<Integer> 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; }