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

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

Description

we'll cut it if the length of the specify string longer than specify length

License

Apache License

Parameter

Parameter Description
str in string
iLen specify length

Return

out string

Declaration

public static String substr(String str, int iLen) 

Method Source Code

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

public class Main {
    /**/* ww w  .  j  a  v  a 2  s  .c  o m*/
     * we'll cut it if the length of the specify string longer than specify length
     *
     * @param str  in string
     * @param iLen specify length
     * @return out string
     */
    public static String substr(String str, int iLen) {
        if (str == null)
            return "";
        if (iLen > 2) {
            if (str.length() > iLen - 2) {
                str = str.substring(0, iLen - 2) + "..";
            }

        }
        return str;
    }
}

Related

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