public static String trimTextDown ( String text , int size ) { if ( text == null || text . length ( ) <= size ) { return text ; } int pos = text . lastIndexOf ( " " , size ) ; if ( pos < 0 ) { return text . substring ( 0 , size ) ; } return text . substring ( 0 , pos ) ; }
Reduces text to max given size preserving words