replaceAfterFirst method

String replaceAfterFirst(
  1. String string,
  2. String replacement
)

Replace after the first occurrence of a string.

Implementation

String replaceAfterFirst(String string, String replacement) {
  if (this == null) {
    throw ArgumentError('string: $this');
  }
  if (this!.isEmpty) {
    return '';
  }
  final index = this!.indexOf(string);
  if (index == -1) {
    return this!;
  }
  return this!.substring(0, index + string.length) + replacement;
}