Java String Sub String subString(String src, String begin, String end)

Here you can find the source of subString(String src, String begin, String end)

Description

sub String

License

Apache License

Declaration

public static String subString(String src, String begin, String end) 

Method Source Code

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

public class Main {

    public static String subString(String src, String begin, String end) {
        return subString(src, 0, begin, end);
    }//from   w  w w.  j  a  va  2  s.  c om

    public static String subString(String src, int offset, String begin, String end) {
        if (isEmpty(src) || offset >= src.length())
            return "";
        int b = offset;
        int e = src.length();
        if (!isEmpty(begin)) {
            b = src.indexOf(begin, offset);
            if (b < 0)
                return "";
            b += begin.length();
        }
        if (!isEmpty(end) && b < e) {
            e = src.indexOf(end, b);
            if (e < 0)
                e = src.length();
        }
        return src.substring(b, e);
    }

    public static boolean isEmpty(String str) {
        return str == null || (str.trim().length() == 0);
    }
}

Related

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