Simple isn't it? The use of this static method allows you to set a maximum length of the sentence to be truncated and then append it with the trailing "...".
public static String truncate(String text, int length) {
return (text.length() <= length) ? text : text.substring(0, length) + " ...";
}
Update: The code is also available in Python in this entry
0 comments:
Post a Comment