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