@Test public void testTrimTrailingCharacter() { Assert.assertEquals("foo", StringUtils.trimTrailingCharacter("foo!", '!')); Assert.assertEquals("", StringUtils.trimTrailingCharacter("", '!')); Assert.assertEquals("", StringUtils.trimTrailingCharacter("!", '!')); }
public static String trimTrailingCharacter(String str, char trailingCharacter) { if(!hasLength(str)) { return str; } else { StringBuilder sb = new StringBuilder(str); while(sb.length() > 0 && sb.charAt(sb.length() - 1) == trailingCharacter) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); } }
StringUtils { public static String trimTrailingCharacter(String str, char trailingCharacter) { if(!hasLength(str)) { return str; } else { StringBuilder sb = new StringBuilder(str); while(sb.length() > 0 && sb.charAt(sb.length() - 1) == trailingCharacter) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); } } }
StringUtils { public static String trimTrailingCharacter(String str, char trailingCharacter) { if(!hasLength(str)) { return str; } else { StringBuilder sb = new StringBuilder(str); while(sb.length() > 0 && sb.charAt(sb.length() - 1) == trailingCharacter) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); } } StringUtils(); }
StringUtils { public static String trimTrailingCharacter(String str, char trailingCharacter) { if(!hasLength(str)) { return str; } else { StringBuilder sb = new StringBuilder(str); while(sb.length() > 0 && sb.charAt(sb.length() - 1) == trailingCharacter) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); } } StringUtils(); static String cause(Throwable t); static String objectToString(Object obj); static String classname(Class<?> clazz); static String normalizeClassName(String className); static String concat(String separator, Class<?>... types); static String concat(String separator, String... strs); static String modifier(int mod, char splitter); static String wrap(String string, int width); static boolean isEmpty(Object str); static boolean hasLength(CharSequence str); static boolean hasLength(String str); static boolean hasText(CharSequence str); static boolean hasText(String str); static boolean containsWhitespace(CharSequence str); static boolean containsWhitespace(String str); static String trimWhitespace(String str); static String trimAllWhitespace(String str); static String trimLeadingWhitespace(String str); static String trimTrailingWhitespace(String str); static String trimLeadingCharacter(String str, char leadingCharacter); static String trimTrailingCharacter(String str, char trailingCharacter); static boolean startsWithIgnoreCase(String str, String prefix); static boolean endsWithIgnoreCase(String str, String suffix); static boolean substringMatch(CharSequence str, int index, CharSequence substring); static String substringAfter(String str, String separator); static String substringBeforeLast(String str, String separator); static String substringBefore(final String str, final String separator); static String substringAfterLast(String str, String separator); static int countOccurrencesOf(String str, String sub); static String replace(String inString, String oldPattern, String newPattern); static String delete(String inString, String pattern); static String deleteAny(String inString, String charsToDelete); static String quote(String str); static Object quoteIfString(Object obj); static String unqualify(String qualifiedName); static String unqualify(String qualifiedName, char separator); static String capitalize(String str); static String uncapitalize(String str); static String[] toStringArray(Collection<String> collection); static String[] split(String toSplit, String delimiter); static Properties splitArrayElementsIntoProperties(String[] array, String delimiter); static Properties splitArrayElementsIntoProperties(String[] array, String delimiter, String charsToDelete); static String[] tokenizeToStringArray(String str, String delimiters); static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens); static String[] delimitedListToStringArray(String str, String delimiter); static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete); static String[] commaDelimitedListToStringArray(String str); static Set<String> commaDelimitedListToSet(String str); static String join(Object[] array, String separator); static boolean isBlank(final CharSequence cs); static String repeat(final char ch, final int repeat); static String repeat(final String str, final int repeat); static int length(final CharSequence cs); static String stripEnd(final String str, final String stripChars); static String classLoaderHash(Class<?> clazz); static String humanReadableByteCount(long bytes); }
StringUtils { public static String trimTrailingCharacter(String str, char trailingCharacter) { if(!hasLength(str)) { return str; } else { StringBuilder sb = new StringBuilder(str); while(sb.length() > 0 && sb.charAt(sb.length() - 1) == trailingCharacter) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); } } StringUtils(); static String cause(Throwable t); static String objectToString(Object obj); static String classname(Class<?> clazz); static String normalizeClassName(String className); static String concat(String separator, Class<?>... types); static String concat(String separator, String... strs); static String modifier(int mod, char splitter); static String wrap(String string, int width); static boolean isEmpty(Object str); static boolean hasLength(CharSequence str); static boolean hasLength(String str); static boolean hasText(CharSequence str); static boolean hasText(String str); static boolean containsWhitespace(CharSequence str); static boolean containsWhitespace(String str); static String trimWhitespace(String str); static String trimAllWhitespace(String str); static String trimLeadingWhitespace(String str); static String trimTrailingWhitespace(String str); static String trimLeadingCharacter(String str, char leadingCharacter); static String trimTrailingCharacter(String str, char trailingCharacter); static boolean startsWithIgnoreCase(String str, String prefix); static boolean endsWithIgnoreCase(String str, String suffix); static boolean substringMatch(CharSequence str, int index, CharSequence substring); static String substringAfter(String str, String separator); static String substringBeforeLast(String str, String separator); static String substringBefore(final String str, final String separator); static String substringAfterLast(String str, String separator); static int countOccurrencesOf(String str, String sub); static String replace(String inString, String oldPattern, String newPattern); static String delete(String inString, String pattern); static String deleteAny(String inString, String charsToDelete); static String quote(String str); static Object quoteIfString(Object obj); static String unqualify(String qualifiedName); static String unqualify(String qualifiedName, char separator); static String capitalize(String str); static String uncapitalize(String str); static String[] toStringArray(Collection<String> collection); static String[] split(String toSplit, String delimiter); static Properties splitArrayElementsIntoProperties(String[] array, String delimiter); static Properties splitArrayElementsIntoProperties(String[] array, String delimiter, String charsToDelete); static String[] tokenizeToStringArray(String str, String delimiters); static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens); static String[] delimitedListToStringArray(String str, String delimiter); static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete); static String[] commaDelimitedListToStringArray(String str); static Set<String> commaDelimitedListToSet(String str); static String join(Object[] array, String separator); static boolean isBlank(final CharSequence cs); static String repeat(final char ch, final int repeat); static String repeat(final String str, final int repeat); static int length(final CharSequence cs); static String stripEnd(final String str, final String stripChars); static String classLoaderHash(Class<?> clazz); static String humanReadableByteCount(long bytes); static final int INDEX_NOT_FOUND; }