Java String Shorten shorten(String s, int len)

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

Description

Shortens the string "s" to a length of "len" characters.

License

Open Source License

Declaration

public static String shorten(String s, int len) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  w  w w  .j  a v  a  2  s .com
     * Shortens the string "s" to a length of "len" characters.
     */
    public static String shorten(String s, int len) {
        if (s == null)
            return null;
        if (s.length() > len)
            s = s.substring(0, len - 2) + "..";
        return s;
    }

    /**
     * Shortens the string "s" to a length of 70 characters.
     */
    public static String shorten(String s) {
        if (s == null)
            return null;
        if (s.length() > 70)
            s = s.substring(0, 67) + "...";
        return s;
    }
}

Related

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