Java String Abbreviate abbreviate(String longName)

Here you can find the source of abbreviate(String longName)

Description

Abbreviate a string.

License

Open Source License

Parameter

Parameter Description
longName The string to be abbreviated.

Return

The possibly abbreviated name.

Declaration

public static String abbreviate(String longName) 

Method Source Code

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

public class Main {
    /** Abbreviate a string.
     *  If the string is longer than 80 characters, truncate it by
     *  displaying the first 37 chars, then ". . .", then the last 38
     *  characters.// w  w w.  ja  v a2s .  c om
     *  If the <i>longName</i> argument is null, then the string
     *  "&gt;Unnamed&lt;" is returned.
     *  @param longName The string to be abbreviated.
     *  @return The possibly abbreviated name.
     *  @see #split(String)
     */
    public static String abbreviate(String longName) {
        // This method is used to abbreviate window titles so that long
        // file names may appear in the window title bar.  It is not
        // parameterized so that we can force a unified look and feel.
        // FIXME: it would be nice to split on a nearby space. 
        if (longName == null) {
            return "<Unnamed>";
        }

        if (longName.length() <= 80) {
            return longName;
        }

        return longName.substring(0, 37) + ". . ." + longName.substring(longName.length() - 38);
    }
}

Related

  1. abbreviate(final String value, int max)
  2. abbreviate(String _str, int _length)
  3. abbreviate(String content, int maxWidth, String enc, String suffix)
  4. abbreviate(String fileName, int maxLen)
  5. abbreviate(String input, int length)
  6. abbreviate(String longStr, int maxLength)
  7. abbreviate(String name)
  8. abbreviate(String s, int length)
  9. abbreviate(String s, int max)