@Test public void testSubstringAfterLast() { Assert.assertEquals("bar", StringUtils.substringAfterLast("foo-bar", "-")); Assert.assertEquals("6", StringUtils.substringAfterLast("123456", "12345")); Assert.assertEquals("", StringUtils.substringAfterLast("foo", "foo")); Assert.assertEquals("", StringUtils.substringAfterLast("foo", "")); Assert.assertEquals("", StringUtils.substringAfterLast("", "")); }
public static String substringAfterLast(String str, String separator) { if (isEmpty(str)) { return str; } else if (isEmpty(separator)) { return ""; } else { int pos = str.lastIndexOf(separator); return pos != -1 && pos != str.length() - separator.length() ? str.substring(pos + separator.length()) : ""; } }
StringUtils { public static String substringAfterLast(String str, String separator) { if (isEmpty(str)) { return str; } else if (isEmpty(separator)) { return ""; } else { int pos = str.lastIndexOf(separator); return pos != -1 && pos != str.length() - separator.length() ? str.substring(pos + separator.length()) : ""; } } }
StringUtils { public static String substringAfterLast(String str, String separator) { if (isEmpty(str)) { return str; } else if (isEmpty(separator)) { return ""; } else { int pos = str.lastIndexOf(separator); return pos != -1 && pos != str.length() - separator.length() ? str.substring(pos + separator.length()) : ""; } } StringUtils(); }
StringUtils { public static String substringAfterLast(String str, String separator) { if (isEmpty(str)) { return str; } else if (isEmpty(separator)) { return ""; } else { int pos = str.lastIndexOf(separator); return pos != -1 && pos != str.length() - separator.length() ? str.substring(pos + separator.length()) : ""; } } 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 substringAfterLast(String str, String separator) { if (isEmpty(str)) { return str; } else if (isEmpty(separator)) { return ""; } else { int pos = str.lastIndexOf(separator); return pos != -1 && pos != str.length() - separator.length() ? str.substring(pos + separator.length()) : ""; } } 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; }