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