Java String Truncate truncate(String s, int maxLength)

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

Description

truncate

License

Open Source License

Declaration

public static String truncate(String s, int maxLength) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014,2015 Hideki Yatomi
 * 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
 ******************************************************************************/

public class Main {
    public static String truncate(String s, int maxLength) {
        if (s.length() > maxLength) {
            StringBuilder sb = new StringBuilder();
            sb.append(s.substring(0, maxLength - 3));
            sb.append("...");
            return sb.toString();
        }//from   ww  w.  j a v a 2  s  . c o  m
        return s;
    }
}

Related

  1. truncate(String s, int i)
  2. truncate(String s, int length)
  3. truncate(String s, int length)
  4. truncate(String s, int length, boolean indicator)
  5. truncate(String s, int max_len)
  6. truncate(String s, int maxLength)
  7. truncate(String s, int maxLength, boolean alignRight)
  8. truncate(String s, int stop, String suf)
  9. truncate(String s, int truncLength, boolean removeWhiteSpace)