Java String Truncate truncString(String in, int len)

Here you can find the source of truncString(String in, int len)

Description

Simple static method to tuncate Strings to given length.

License

Apache License

Parameter

Parameter Description
in the string that may need tuncating.
len the lenght that the string should be truncated to.

Return

a new String containing chars with length <= len or null if input String is null.

Declaration

public static String truncString(String in, int len) 

Method Source Code

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

public class Main {
    /**//from   w  w  w . ja v  a2 s .com
     * Simple static method to tuncate Strings to given length.
     * @param in the string that may need tuncating.
     * @param len the lenght that the string should be truncated to.
     * @return a new String containing chars with length <= len or <code>null</code>
     * if input String is <code>null</code>.
     */
    public static String truncString(String in, int len) {
        String out = in;
        if (in != null && len > 0 && in.length() > len) {
            out = in.substring(0, len);
        }
        return out;
    }
}

Related

  1. truncateWhenUTF8(final String s, final int maxBytes)
  2. truncateWhiteSpace(int len, int tabSize, String indentStr)
  3. truncateWithDefault(String value, int size, String defaultValue)
  4. truncateWithEllipsis(String str, int maxLength)
  5. truncAtWord(String a_text, int a_length)
  6. truncuate(String s, int maximumLength, String append)
  7. truncVal(String s)