Here you can find the source of ellipsize(String string, int length)
Parameter | Description |
---|---|
string | of text |
length | to cut string down to |
public static String ellipsize(String string, int length)
//package com.java2s; //License from project: Open Source License public class Main { /**//from ww w .j a v a 2 s .co m * Ellipsize a string, keeping it readable * * @param string * of text * @param length * to cut string down to * @return The ellipsied string. */ public static String ellipsize(String string, int length) { String ellipsis = "..."; if (length >= string.length()) { return string; } int trim = length - ellipsis.length(); return string.substring(0, trim / 2) + ellipsis + string.substring(string.length() - trim / 2); } }