private static String trimTrailingWhitespace ( String string ) { int end = 0 ; char c ; for ( int i = string . length ( ) - 1 ; i >= 0 ; i -- ) { c = string . charAt ( i ) ; if ( ! Character . isWhitespace ( c ) ) { end = i ; break ; } } if ( end == 0 ) { return string ; } return string . substring ( 0 , end + 1 ) ; }
Returns a string that contains a copy of a specified string without trailing whitespaces .