Java String Shorten shortenMiddle(String msg, int maxLen)

Here you can find the source of shortenMiddle(String msg, int maxLen)

Description

Inserts "..."

License

Open Source License

Parameter

Parameter Description
msg a parameter
maxLen a parameter

Declaration

public static String shortenMiddle(String msg, int maxLen) 

Method Source Code

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

public class Main {
    /**/*from   w  w w.j  av a2  s .c  o  m*/
     * Inserts "..." inside the String and shortens it to maxLen.
     * @param msg
     * @param maxLen
     * @return
     */
    public static String shortenMiddle(String msg, int maxLen) {
        if (msg.length() <= maxLen)
            return msg;
        int half = (maxLen - 3) / 2;
        return msg.substring(0, half) + "..." + msg.substring(msg.length() - half);
    }
}

Related

  1. shortenFileName(String name)
  2. shortenFileName(String text, String filename)
  3. shortenGeneratedIdentifier(final String name)
  4. shortenHash(String s)
  5. shortenLabel(String key)
  6. shortenName(final String fullName)
  7. shortenName(final String name, final int toBeAdded)
  8. shortenName(String name)
  9. shortenOperationName(String operation)