removeLastOccurrence method

  1. @useResult
String removeLastOccurrence(
  1. String target
)

Returns a new string with the last occurrence of target removed.

Implementation

@useResult
String removeLastOccurrence(String target) {
  final int lastIndex = lastIndexOf(target);
  if (lastIndex == -1) {
    return this;
  }

  return substringSafe(0, lastIndex) + substringSafe(lastIndex + target.length);
}