replaceFirst method

String? replaceFirst(
  1. Pattern from,
  2. String to, [
  3. int startIndex = 0
])

Creates a new string with the first occurrence of from replaced by to.

Finds the first match of from in this string, starting from startIndex, and creates a new string where that match is replaced with the to string.

Example:

'0.0001'.replaceFirst(RegExp(r'0'), ''); // '.0001'
'0.0001'.replaceFirst(RegExp(r'0'), '7', 1); // '0.7001'

Implementation

String? replaceFirst(Pattern from, String to, [int startIndex = 0]) =>
    value?.replaceFirst(from, to, startIndex);