public static String trimRight ( String string ) { for ( int i = string . length ( ) ; i > 0 ; -- i ) { if ( string . charAt ( i - 1 ) != ' ' && string . charAt ( i - 1 ) != ' ' && string . charAt ( i - 1 ) != ' ' && string . charAt ( i - 1 ) != ' ' ) { return i == string . length ( ) ? string : string . substring ( 0 , i ) ; } } return "" ; }
Removes all whitespace characters from the end of the string .