public static String truncate ( String str , int count ) { if ( count < 0 || str . length ( ) <= count ) return str ; int pos = count ; for ( int i = count ; i >= 0 && ! Character . isWhitespace ( str . charAt ( i ) ) ; i -- , pos -- ) ; return str . substring ( 0 , pos ) + "..." ; }
Returns the given string truncated at a word break before the given number of characters .