Java String Truncate trunc(String str, int length)

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

Description

truncate a String to the desired length

License

Open Source License

Declaration

private static String trunc(String str, int length) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  w w w .j  a  v  a 2s  .c  om
    * truncate a String to the desired length
    */
    private static String trunc(String str, int length) {
        if (str == null)
            str = "Error";
        else if (str.length() >= length)
            str = str.substring(0, length);
        return str;
    }
}

Related

  1. trunc(String in, int len)
  2. trunc(String s, int length)
  3. trunc(String s1, int length)
  4. trunc(String string, int length)
  5. trunc(String txt, int size)
  6. trunc(String value, int len)
  7. truncate(final String description)