Android String Shorten ellipsize(final String text, final int length)

Here you can find the source of ellipsize(final String text, final int length)

Description

Ellipsizes a text

Parameter

Parameter Description
text the text to ellipsize
length the max length of the return string

Return

an ellipsized string which contains at most lengt characters

Declaration

public static String ellipsize(final String text, final int length) 

Method Source Code

//package com.java2s;

import android.text.TextUtils;

public class Main {
    /**//w  ww .j  av a  2 s .  com
     * Ellipsizes a text
     * 
     * @param text
     *            the text to ellipsize
     * @param length
     *            the max length of the return string
     * @return an ellipsized string which contains at most lengt characters
     */
    public static String ellipsize(final String text, final int length) {
        String result;

        if (TextUtils.isEmpty(text)) {
            result = "";
        } else {
            result = text;
            if (result.length() > length) {
                result = result.substring(0, length - 6) + " [...]";
            }
        }

        return result;
    }
}

Related

  1. curtail(String str, int size, String tail)
  2. truncateString(String resource, String startTag, String endTag)
  3. truncateAtMaxLength(String source, int maxLength, boolean addEllipsis)
  4. shortenString(String str, int length)
  5. ellipsizeString(String string, int limit)