Java String Truncate truncate(String str)

Here you can find the source of truncate(String str)

Description

Shortens the given string if its length exceeds a fixed limit.

License

Open Source License

Declaration

public static String truncate(String str) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2008 Tran Nam Quang.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  w ww  . j a  va2s  . c  o  m*/
 *    Tran Nam Quang - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Shortens the given string if its length exceeds a fixed limit.
     */
    public static String truncate(String str) {
        if (str.length() > 32)
            return str.substring(0, 32) + "..."; //$NON-NLS-1$
        return str;
    }
}

Related

  1. truncate(String s, int maxLength, boolean alignRight)
  2. truncate(String s, int stop, String suf)
  3. truncate(String s, int truncLength, boolean removeWhiteSpace)
  4. truncate(String source, int maxLength, String cutoffReplacement)
  5. truncate(String src, int maxChars, boolean addEllipses)
  6. truncate(String str, int byteLength)
  7. truncate(String str, int chars)
  8. truncate(String str, int len)
  9. truncate(String str, int length)