Java String Truncate truncateString(String str, int maxlen)

Here you can find the source of truncateString(String str, int maxlen)

Description

truncate String

License

Apache License

Declaration

public static String truncateString(String str, int maxlen) 

Method Source Code

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

public class Main {
    public static String truncateString(String str, int maxlen) {
        return truncateString(str, maxlen, false);
    }// w  ww  .  j  a  v  a  2s.  c om

    public static String truncateString(String str, int maxlen, boolean elipsis) {
        if (str == null)
            return "";
        if (elipsis)
            maxlen -= 3;
        if (str.length() > maxlen)
            str = str.substring(0, maxlen);
        if (elipsis)
            return str + "...";
        else
            return str;
    }
}

Related

  1. truncateString(String s, int numChars)
  2. truncateString(String source, int prefixLength, int totalLength)
  3. truncateString(String source, String suffix)
  4. truncateString(String str, int length)
  5. truncateString(String str, int length, String suffix)
  6. truncateString(String str, int size)
  7. truncateString(String str, int toLen)
  8. truncateString(String string, int maxLength)
  9. truncateString(String text, int truncateAt)