Android examples for java.lang:String Shorten
add Ellipsis to string
import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ public static String addEllipsis(String src, String ellipsis, int maxLength) { if (maxLength < 0) { throw new IllegalArgumentException( "maxLength could not less than zero"); }/*from w ww . ja v a 2s . co m*/ int srcLength = src.length(); if (srcLength <= maxLength) { return src; } int ellipsisLength = ellipsis.length(); int dis = srcLength + ellipsisLength - maxLength; if (dis < srcLength) { return src.substring(0, srcLength - dis) + ellipsis; } return ellipsis.substring(dis - srcLength); } }