replaceBeforeLast method
Replace before the last occurrence of a string.
Implementation
String replaceBeforeLast(String string, String replacement) {
if (this == null) {
throw ArgumentError('string: $this');
}
if (this!.isEmpty) {
return '';
}
final index = this!.lastIndexOf(string);
if (index == -1) {
return this!;
}
return replacement + this!.substring(index);
}