Java String Shorten shorten(String s, int length)

Here you can find the source of shorten(String s, int length)

Description

Shorten a string using elipses (...)

License

Open Source License

Parameter

Parameter Description
s String to shorten
length shortened length where elipses will start

Return

shortened string.

Declaration

public static final String shorten(String s, int length) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w ww .  j a v a  2  s .  c  om*/
     * Shorten a string using elipses (...)
     *
     * @param s      String to shorten
     * @param length shortened length where elipses will start
     * @return shortened string.
     */
    public static final String shorten(String s, int length) {
        if (s.length() > length) {
            s = s.substring(0, length - 1) + "...";
        }
        return s;
    }
}

Related

  1. shorten(String s)
  2. shorten(String s)
  3. shorten(String s)
  4. shorten(String s)
  5. shorten(String s, int len)
  6. shorten(String s, int length, String suffix)
  7. shorten(String s, int length, String suffix)
  8. shorten(String s, int max)
  9. shorten(String s, int maxLength)