Here you can find the source of shorten(String string, int upTo)
Parameter | Description |
---|---|
string | the string to shorten |
upTo | the up to |
public static String shorten(String string, int upTo)
//package com.java2s; //License from project: LGPL public class Main { /**//from w w w . j a v a 2s . c o m * Shorten the given string if the string is more than the given length. * <p> * Example:<br> * <code> * System.out.println(LoggingUtil.shorten("The quick brown fox jumps over the lazy dog", 10)); * </code><br> * Prints:<br> * <code>The quick... 33 more</code> * * @param string * the string to shorten * @param upTo * the up to * @return the string */ public static String shorten(String string, int upTo) { if (string.length() > upTo) { StringBuilder builder = new StringBuilder(upTo + 10); return builder.append(string.substring(0, upTo)).append("... ").append(string.length() - upTo) .append(" more").toString(); } return string; } }