Java String Sub String substr(String str, int beginIndex, int endIndex)

Here you can find the source of substr(String str, int beginIndex, int endIndex)

Description

substr

License

Open Source License

Declaration

public static String substr(String str, int beginIndex, int endIndex) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static String substr(String str, int beginIndex, int endIndex) {
        if (isBlank(str)) {
            return "";
        }/*from  w  w w  .j  a  v  a 2  s.  c om*/
        if (endIndex == -1) {
            return str.substring(beginIndex);
        }

        if (endIndex > str.length()) {
            endIndex = str.length();
        }
        return str.substring(beginIndex, endIndex);
    }

    public String substr(String str, int beginIndex, int endIndex, String endMark) {
        if (isBlank(str)) {
            return "";
        }
        if (endIndex == -1) {
            return str.substring(beginIndex);
        }

        if (endIndex > str.length()) {
            endIndex = str.length();
        }
        String restr = str.substring(beginIndex, endIndex);
        if (endIndex < str.length()) {
            restr = restr + endMark;
        }
        return restr;
    }

    public static boolean isBlank(String str) {
        if (isEmpty(str))
            return true;
        for (int i = 0; i < str.length(); i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

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

Related

  1. substr(String s, String sub, boolean before)
  2. substr(String src, int beginIndex, int endIndex)
  3. subStr(String src, int len)
  4. substr(String src, int nStart, int nLen)
  5. subStr(String src, String split)
  6. substr(String str, int iLen)
  7. substr(String str, int index)
  8. subStr(String str, int len)
  9. substr(String str, int length)