@@ -8690,6 +8690,41 @@ public static String substringBefore(final String str, final String separator) {
8690
8690
}
8691
8691
return str .substring (0 , pos );
8692
8692
}
8693
+
8694
+ /**
8695
+ * Gets the substring before the last occurrence of a separator.
8696
+ * The separator is not returned.
8697
+ *
8698
+ * <p>A {@code null} string input will return {@code null}.
8699
+ * An empty ("") string input will return the empty string.</p>
8700
+ *
8701
+ * <p>If nothing is found, the string input is returned.</p>
8702
+ *
8703
+ * <pre>
8704
+ * StringUtils.substringBeforeLast(null, *) = null
8705
+ * StringUtils.substringBeforeLast("", *) = ""
8706
+ * StringUtils.substringBeforeLast("abcba", 'b') = "abc"
8707
+ * StringUtils.substringBeforeLast("abc", 'c') = "ab"
8708
+ * StringUtils.substringBeforeLast("a", 'a') = ""
8709
+ * StringUtils.substringBeforeLast("a", 'z') = "a"
8710
+ * </pre>
8711
+ *
8712
+ * @param str the String to get a substring from, may be null
8713
+ * @param separator the character (Unicode code point) to search.
8714
+ * @return the substring before the last occurrence of the separator,
8715
+ * {@code null} if null String input
8716
+ * @since 3.12.1
8717
+ */
8718
+ public static String substringBeforeLast (final String str , final int separator ) {
8719
+ if (isEmpty (str )) {
8720
+ return str ;
8721
+ }
8722
+ final int pos = str .lastIndexOf (separator );
8723
+ if (pos == INDEX_NOT_FOUND ) {
8724
+ return str ;
8725
+ }
8726
+ return str .substring (0 , pos );
8727
+ }
8693
8728
8694
8729
/**
8695
8730
* Gets the substring before the last occurrence of a separator.
0 commit comments