Java String Truncate truncate(String message, int length, boolean includeCount)

Here you can find the source of truncate(String message, int length, boolean includeCount)

Description

truncate

License

Open Source License

Declaration

public static String truncate(String message, int length, boolean includeCount) 

Method Source Code

//package com.java2s;
/*//from  w  w  w .  j  a  v a2  s . c o m
 * $Id$
 * --------------------------------------------------------------------------------------
 * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 *
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */

public class Main {
    public static String truncate(String message, int length, boolean includeCount) {
        if (message == null) {
            return null;
        }
        if (message.length() <= length) {
            return message;
        }
        String result = message.substring(0, length) + "...";
        if (includeCount) {
            result += "[" + length + " of " + message.length() + "]";
        }
        return result;
    }
}

Related

  1. truncate(String eval, String suffix, int targetLength)
  2. truncate(String input, int maxLength)
  3. truncate(String input, int maxLength)
  4. truncate(String input, int size)
  5. truncate(String message)
  6. truncate(String message, String substring)
  7. truncate(String original, int number)
  8. truncate(String original, String ellipsis, int maxLength)
  9. truncate(String originalString, int size)