Here you can find the source of ellipsis(final String text, final int length)
Parameter | Description |
---|---|
text | the string to truncate |
length | the size (if 0 returns the same text, if null return an empty string) |
public static String ellipsis(final String text, final int length)
//package com.java2s; /*/*from ww w . j a v a2 s. c o m*/ * ((e)) emite: A pure Google Web Toolkit XMPP library * Copyright (c) 2008-2011 The Emite development team * * This file is part of Emite. * * Emite is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * Emite is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with Emite. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Ellipsis. * * @param text * the string to truncate * @param length * the size (if 0 returns the same text, if null return an empty * string) * * @return the result string */ public static String ellipsis(final String text, final int length) { return text == null ? "" : length == 0 ? text : text.length() > length ? text.substring(0, length - 3) + "..." : text; } }