Java String Truncate truncateByCharLengthWithEllipsis(String string, int maxLength)

Here you can find the source of truncateByCharLengthWithEllipsis(String string, int maxLength)

Description

truncate By Char Length With Ellipsis

License

Open Source License

Declaration

public static String truncateByCharLengthWithEllipsis(String string, int maxLength) 

Method Source Code

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

public class Main {
    public static String truncateByCharLengthWithEllipsis(String string, int maxLength) {
        return string.length() <= maxLength ? string : truncateByCharLength(string, maxLength - 3) + "...";
    }/*from  w  w  w .  j  a  v  a2 s .c o  m*/

    public static String truncateByCharLength(String string, int maxLength) {
        return string.length() > maxLength ? string.substring(0, maxLength) : string;
    }
}

Related

  1. truncateAtMaxLength(String source, int maxLength, boolean addEllipsis)
  2. truncateAtWhitespace(String text, int length)
  3. truncateAtWord(String input, int length)
  4. truncateBodyText(String input)
  5. truncateByCharLength(String string, int maxLength)
  6. truncateCellValue(String x, int maxChars)
  7. truncateCodeStringIfNeeded(String codeString)
  8. truncateData(String data, int idLength)
  9. truncateDatabaseName(String db)