Java String Sub String substringBetween(String s, String part1, String part2)

Here you can find the source of substringBetween(String s, String part1, String part2)

Description

substring Between

License

Open Source License

Declaration

public static String substringBetween(String s, String part1, String part2) 

Method Source Code

//package com.java2s;

public class Main {
    public static String substringBetween(String s, String part1, String part2) {
        String sub = null;//from ww  w .  j a v a 2s .c  om

        int i = s.indexOf(part1);
        int j = s.indexOf(part2, i + part1.length());

        if (i != -1 && j != -1) {
            int nStart = i + part1.length();
            sub = s.substring(nStart, j);
        }

        return sub;
    }
}

Related

  1. substringBeforeLastIgnoreCase(final String target, final String separator)
  2. substringBetween(final String s, final String tag)
  3. substringBetween(final String str, final String startToken, final String endToken)
  4. substringBetween(String line, final String delimiterBefore, final String delimiterAfter)
  5. substringBetween(String s, String part1, String part2)
  6. substringBetween(String source, String strBegin, String strEnd)
  7. substringBetween(String str, String before, String after)
  8. substringBetween(String str, String open, String close)
  9. substringBetween(String str, String open, String close)