Java String Truncate trunc(String s1, int length)

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

Description

trunc

License

Open Source License

Declaration

public static String trunc(String s1, int length) 

Method Source Code

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

public class Main {
    public static String trunc(String s1, int length) {
        if (s1 == null) {
            return "";
        }// ww w. j av a2 s.  c  o  m
        if (s1.length() > length && length <= 2) {
            return s1.substring(0, length);
        }
        if (s1.length() > length) {
            return s1.substring(0, length - 2) + "..";
        }
        return s1;
    }
}

Related

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