replaceBeforeFirst method

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

Replace before the first occurrence of a string.

Implementation

String replaceBeforeFirst(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 replacement + this!.substring(index);
}