Java String Sub String substr(String str, int length)

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

Description

safe substring, without exception

License

Open Source License

Parameter

Parameter Description
str a parameter
length a parameter

Declaration

public static String substr(String str, int length) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w  ww . j a v  a2  s.  co m*/
     * safe substring, without exception
     * @param str
     * @param length
     * @return
     * @author <a href="mailto:iffiff1@gmail.com">Tyler Chen</a> 
     * @since 2014-9-25
     */
    public static String substr(String str, int length) {
        if (str == null) {
            return str;
        }
        if (length < str.length()) {
            return str.substring(0, length);
        }
        return str;
    }
}

Related

  1. subStr(String src, String split)
  2. substr(String str, int beginIndex, int endIndex)
  3. substr(String str, int iLen)
  4. substr(String str, int index)
  5. subStr(String str, int len)
  6. subStr(String str, int limit)
  7. subStr(String str, int maxLen)
  8. substr(String str, int startIndex, int length)
  9. substr(String substr1, String substr2)