replaceBeforeLast method

String replaceBeforeLast(
  1. String pattern,
  2. String replacement
)

Replaces everything before the last occurrence of pattern.

Implementation

String replaceBeforeLast(String pattern, String replacement) {
  final i = lastIndexOf(pattern);
  if (i == -1) return this;
  return replacement + substring(i);
}