Here you can find the source of abbreviate(String _str, int _length)
Parameter | Description |
---|---|
_str | string to abbrivate |
_length | max length |
public static String abbreviate(String _str, int _length)
//package com.java2s; //License from project: Open Source License public class Main { /**//w w w . j av a 2 s . co m * Abbreviates a String using ellipses. * * @param _str string to abbrivate * @param _length max length * @return abbreviated string, original string if string length is lower or equal then desired length or null if input was null */ public static String abbreviate(String _str, int _length) { if (_str == null) { return null; } if (_str.length() <= _length) { return _str; } String abbr = _str.substring(0, _length - 3) + "..."; return abbr; } }