Java String Sub String substring(String src, String fromToken, String toToken)

Here you can find the source of substring(String src, String fromToken, String toToken)

Description

substring

License

Apache License

Declaration

public static String substring(String src, String fromToken, String toToken) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String substring(String src, String fromToken, String toToken) {
        int from = src.indexOf(fromToken);
        if (from == -1)
            return null;
        from += fromToken.length();/*from   w w  w  .  j a  v a 2s  .  c  o m*/
        int to = src.indexOf(toToken, from);
        if (to == -1) {
            return src.substring(from);
        }
        return src.substring(from, to);
    }

    public static int indexOf(String nextLine, char c) {
        int length = nextLine.length();
        for (int i = 0; i < length; i++) {
            if (c == nextLine.charAt(i))
                return i;
        }
        return -1;
    }

    public static int indexOf(String nextLine, char[] chars) {
        int length = nextLine.length();
        for (int i = 0; i < length; i++) {
            for (char c : chars) {
                if (c == nextLine.charAt(i))
                    return i;
            }
        }

        return -1;
    }
}

Related

  1. subString(String source, int startIndex, int count)
  2. substring(String src, int beginIndex, int endIndex)
  3. substring(String src, int start_idx, int end_idx)
  4. subString(String src, int startIndex, int endIndex)
  5. subString(String src, String begin, String end)
  6. subString(String src, String start, String to)
  7. subString(String src, String start, String to)
  8. subString(String srcStr, int subLen)
  9. substring(String str, char pattern)