Java String Abbreviate abbreviate(String str, int maxWidth)

Here you can find the source of abbreviate(String str, int maxWidth)

Description

abbreviate

License

Mozilla Public License

Declaration

public static String abbreviate(String str, int maxWidth) 

Method Source Code

//package com.java2s;
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/*from   w  ww  .j a va  2  s .co m*/
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Spindle, an Eclipse Plugin for Tapestry.
 *
 * The Initial Developer of the Original Code is
 * Geoffrey Longman.
 * Portions created by the Initial Developer are Copyright (C) 2001-2005
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 * 
 *  glongman@gmail.com
 *
 * ***** END LICENSE BLOCK ***** */

public class Main {
    public static String abbreviate(String str, int maxWidth) {
        if (str == null)
            return null;

        if (maxWidth < 4)
            throw new IllegalArgumentException("Minimum abbreviation width is 4");

        return str.substring(0, maxWidth - 3) + "...";

    }
}

Related

  1. abbreviate(String str, int maxWidth)
  2. abbreviate(String str, int maxWidth)
  3. abbreviate(String str, int maxWidth)
  4. abbreviate(String str, int maxWidth)
  5. abbreviate(String str, int maxWidth)
  6. abbreviate(String str, int maxWidth)
  7. abbreviate(String str, int offset, int maxWidth)
  8. abbreviate(String str, int preferredLength)
  9. abbreviate(String string, int maxLength)