Here you can find the source of shortenMiddle(String msg, int maxLen)
Parameter | Description |
---|---|
msg | a parameter |
maxLen | a parameter |
public static String shortenMiddle(String msg, int maxLen)
//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); } }