Here you can find the source of abbreviate(String str)
Parameter | Description |
---|---|
str | The string which is to be abbreviated. |
public static String abbreviate(String str)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j a va2s.com * Abbreviates a string such that it doesn't straddle more than one line, and isn't very long. * Useful in toString methods where one attribute may be long, and you want to keep the output concise. * * @param str * The string which is to be abbreviated. * @return The abbreviated string or str if no abbreviation was needed. */ public static String abbreviate(String str) { return abbreviate(str, 60); } public static String abbreviate(String str, int limit) { if (str == null) { return null; } if (str.length() > limit) { str = str.substring(0, limit) + "..."; } int nl = str.indexOf("\n"); if (nl >= 0) { str = str.substring(0, nl) + "\\n..."; } return str; } }