Java String Shorten shortenString(String s, int maxLength)

Here you can find the source of shortenString(String s, int maxLength)

Description

If the string s is longer than maxLength , the string is cut and "..."

License

GNU General Public License

Declaration

public static String shortenString(String s, int maxLength) 

Method Source Code

//package com.java2s;
// License: GPL. For details, see LICENSE file.

public class Main {
    /**//from www.  j a v  a  2  s.  c  o  m
     * If the string {@code s} is longer than {@code maxLength}, the string is cut and "..." is appended.
     */
    public static String shortenString(String s, int maxLength) {
        if (s != null && s.length() > maxLength) {
            return s.substring(0, maxLength - 3) + "...";
        } else {
            return s;
        }
    }
}

Related

  1. shortenPath(final String path)
  2. shortenPrefix(String prefix)
  3. shortenRemoteRef(final String origin, final String ref)
  4. shortenString(String orig, int charsToRemove)
  5. shortenString(String orig, int maxLength)
  6. shortenString(String s, int requiredLength)
  7. shortenString(String source, int minLength, int maxLength, String suffix)
  8. shortenString(String str, int i)
  9. shortenString(String string, int minimumLength, int lengthToShortenBy)