/**
     * 获取目标字符串在字符串中第N次出现的位置
     * @file name
     * @author xiehongwei
     * @date 2017-8-2 下午3:29:09
     * @param source    源字符串
     * @param target    目标字符串
     * @param n         出现位置
     * @return
     */
    public static int getCharacterPosition(String source, String target, int n) {
        // 这里是获取目标符号的位置
        Matcher slashMatcher = Pattern.compile(target).matcher(source);
        int mIdx = 0;
        while (slashMatcher.find()) {
            mIdx++;
            // 当目标符号第N次出现的位置
            if (mIdx == n) {
                break;
            }
        }
        return slashMatcher.start();
    }

 

相关文章:

  • 2021-11-20
  • 2021-07-16
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案