Java String Sub String substringBetween(final String str, final String startToken, final String endToken)

Here you can find the source of substringBetween(final String str, final String startToken, final String endToken)

Description

substring Between

License

Open Source License

Declaration

public static String substringBetween(final String str, final String startToken, final String endToken) 

Method Source Code

//package com.java2s;
/**//from  w  w w.  j a v  a  2s .c  om
 * Confidential Information.
 * Copyright (C) 2007-2009 Eric Link, All rights reserved.
 * PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 **/

public class Main {
    public static String substringBetween(final String str, final String startToken, final String endToken) {
        //-1 if not found
        int firstToken = str.indexOf(startToken) + 1;
        int secondToken = str.indexOf(endToken, firstToken);
        // make safe if not found
        firstToken = firstToken < 0 ? 0 : firstToken;
        secondToken = secondToken < 0 ? 0 : secondToken;
        return str.substring(firstToken, secondToken);
    }
}

Related

  1. subStringBeforeLast(String str, String separator)
  2. substringBeforeLast(String text, String separator)
  3. substringBeforeLastChar(String str, String separator)
  4. substringBeforeLastIgnoreCase(final String target, final String separator)
  5. substringBetween(final String s, final String tag)
  6. substringBetween(String line, final String delimiterBefore, final String delimiterAfter)
  7. substringBetween(String s, String part1, String part2)
  8. substringBetween(String s, String part1, String part2)
  9. substringBetween(String source, String strBegin, String strEnd)