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