replaceLast method
Replaces the last occurrence of oldValue with newValue.
Example:
'hello hello'.replaceLast('hello', 'hi'); // 'hello hi'
Implementation
String replaceLast(String oldValue, String newValue) {
final index = lastIndexOf(oldValue);
if (index == -1) return this;
return '${substring(0, index)}$newValue${substring(index + oldValue.length)}';
}