Java String Ellipse ellipsis(final String text, final int length)

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

Description

Ellipsis.

License

Open Source License

Parameter

Parameter Description
text the string to truncate
length the size (if 0 returns the same text, if null return an empty string)

Return

the result string

Declaration

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

Method Source Code

//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;
    }
}

Related

  1. ellipseCircum(double a, double b)
  2. ellipseCircumference(double a, double b)
  3. ellipseString(StringBuilder builder, int maxLength)
  4. ellipsify(String message)
  5. ellipsis(final String text, int length)
  6. ellipsis(String string, int length)
  7. ellipsis(String text, int max)
  8. ellipsis(String text, int maxLength)