replaceRange method

String replaceRange(
  1. int start,
  2. int? end,
  3. String replacement
)

Replaces the substring from start to end with replacement.

Creates a new string equivalent to:

this.substring(0, start) + replacement + this.substring(end)

Example:

const string = 'Dart is fun';
final result = string.replaceRange(8, null, 'open source');
print(result); // Dart is open source

The start and end indices must specify a valid range of this string. That is 0 <= start <= end <= this.length. If end is null, it defaults to length.

Implementation

String replaceRange(int start, int? end, String replacement) =>
    value.replaceRange(start, end, replacement);