Java String Truncate trunc(String s, int length)

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

Description

Takes a string and a length, and truncates it to that that length.

License

Open Source License

Declaration

public static String trunc(String s, int length) 

Method Source Code

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

public class Main {
    /**//from w w  w. j  ava  2  s .c om
     * Takes a string and a length, and truncates it to that that length.
     * Returns the original string if the length is greater than the string length;
     */
    public static String trunc(String s, int length) {
        if (s.length() <= length)
            return s;
        else
            return s.substring(0, length);
    }
}

Related

  1. trunc(String in, int len)
  2. trunc(String s1, int length)
  3. trunc(String str, int length)
  4. trunc(String string, int length)
  5. trunc(String txt, int size)