code: public static String trim(String input, int maxNrofChars, String end) {
  		if (end == null) {
  			end = "";
  		}
  		int margin = end.length();
  		if (input != null && input.length() > maxNrofChars + margin) {
  			input = input.substring(0, maxNrofChars) + end;
  		}
  		return input;
  	}
docs: Trims strings that contain too many characters and adds trailing characters
  to indicate that the original string has been trimmed.
  
  @param input
  @param maxNrofChars maximum allowed length of input
  @param end		  trailing characters when trimmed
  @return original string or trimmed version