code: 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 != '\t'
      		 && charAt != '\n'
      		 && charAt != '\r' ) 
      		{			
      			break;
      		}
      	}
      	
      	if( i <= pos ) 
      	{
      		return "";
      	}
      	
      	return ( 0 == pos && i == string.length() ) ? string : 
      	                                              string.substring( pos, i );
      }
docs: Removes all whitespace characters from the end of the string
  starting from the given position.