Java String Shorten shorten(String string, int size)

Here you can find the source of shorten(String string, int size)

Description

shorten

License

Open Source License

Declaration

public static String shorten(String string, int size) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * This file is part of UserWeave./*w ww .j av  a  2  s  .c  om*/
 *
 *     UserWeave is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Affero General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     UserWeave 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 Affero General Public License for more details.
 *
 *     You should have received a copy of the GNU Affero General Public License
 *     along with UserWeave.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2012 User Prompt GmbH | Psychologic IT Expertise
 *******************************************************************************/

public class Main {
    public static String shorten(String string, int size) {
        if (string == null) {
            return null;
        }

        if (size < string.length()) {
            return string.substring(0, size - 1) + "...";
        } else {
            return string;
        }
    }
}

Related

  1. shorten(String s, int maxLength)
  2. shorten(String script, int length)
  3. shorten(String str, int length)
  4. shorten(String str, int length)
  5. shorten(String string, boolean isPrefix)
  6. shorten(String string, int upTo)
  7. shorten(String text, int max)
  8. shorten(String text, int size, int mode)
  9. shorten(String[] a, int from, int to)