replaceLast static method

String replaceLast(
  1. String search,
  2. String replace,
  3. String subject
)

Replaces the last occurrence of search with replace in subject.

Implementation

static String replaceLast(String search, String replace, String subject) {
  if (search.isEmpty) return subject;
  final index = subject.lastIndexOf(search);
  if (index == -1) return subject;
  return subject.replaceFirst(search, replace, index);
}