Enjoy.
/**
* Provides a text that will match a desired dimension, reducing
* it if necessary.
*/
public static String shortText(String text, int maxLength){
String result = text;
// if this text portion is bigger than allowed, reduce
if(text.length() > maxLength){
int half = maxLength / 2;
int length = text.length();
result = text.substring(0, half) + ".."
+ text.substring(length - half, length);
}
return result;
}
No comments:
Post a Comment