getEverythingAfterLast method

  1. @useResult
String getEverythingAfterLast(
  1. String find
)

Returns the substring after the last occurrence of find.

Returns the original string if find is not found or is empty. Safe for emoji and combining marks anywhere in the string.

Example:

'a-b-c'.getEverythingAfterLast('-');  // 'c'
'👋a-b'.getEverythingAfterLast('-');  // 'b'

Audited: 2026-06-12 11:26 EDT

Implementation

@useResult
String getEverythingAfterLast(String find) {
  if (find.isEmpty) {
    return this;
  }

  final int atIndex = lastIndexOf(find);

  return atIndex == -1 ? this : substring(atIndex + find.length);
}