@Test public void shouldTrimWhiteSpaceAndPattern() { final String input = " 111hello11 "; final String trimmed = StringTransforms.trim(input, "1"); Assert.assertEquals("hello", trimmed); }
public static String trim(String input, final String toTrim) { if (input == null) return null; Preconditions.checkNotNull(toTrim); input = input.trim(); while (!input.isEmpty() && input.length() >= toTrim.length() && input.startsWith(toTrim)) input = input.substring(toTrim.length(), input.length()); while (!input.isEmpty() && input.length() >= toTrim.length() && input.endsWith(toTrim)) input = input.substring(0, input.length() - toTrim.length()); return input; }
StringTransforms { public static String trim(String input, final String toTrim) { if (input == null) return null; Preconditions.checkNotNull(toTrim); input = input.trim(); while (!input.isEmpty() && input.length() >= toTrim.length() && input.startsWith(toTrim)) input = input.substring(toTrim.length(), input.length()); while (!input.isEmpty() && input.length() >= toTrim.length() && input.endsWith(toTrim)) input = input.substring(0, input.length() - toTrim.length()); return input; } }
StringTransforms { public static String trim(String input, final String toTrim) { if (input == null) return null; Preconditions.checkNotNull(toTrim); input = input.trim(); while (!input.isEmpty() && input.length() >= toTrim.length() && input.startsWith(toTrim)) input = input.substring(toTrim.length(), input.length()); while (!input.isEmpty() && input.length() >= toTrim.length() && input.endsWith(toTrim)) input = input.substring(0, input.length() - toTrim.length()); return input; }  }
StringTransforms { public static String trim(String input, final String toTrim) { if (input == null) return null; Preconditions.checkNotNull(toTrim); input = input.trim(); while (!input.isEmpty() && input.length() >= toTrim.length() && input.startsWith(toTrim)) input = input.substring(toTrim.length(), input.length()); while (!input.isEmpty() && input.length() >= toTrim.length() && input.endsWith(toTrim)) input = input.substring(0, input.length() - toTrim.length()); return input; }  static String trim(String input, final String toTrim); static String trim(final String input, final char toTrim); }
StringTransforms { public static String trim(String input, final String toTrim) { if (input == null) return null; Preconditions.checkNotNull(toTrim); input = input.trim(); while (!input.isEmpty() && input.length() >= toTrim.length() && input.startsWith(toTrim)) input = input.substring(toTrim.length(), input.length()); while (!input.isEmpty() && input.length() >= toTrim.length() && input.endsWith(toTrim)) input = input.substring(0, input.length() - toTrim.length()); return input; }  static String trim(String input, final String toTrim); static String trim(final String input, final char toTrim);  }