replaceFirstMapped method
Replace the first occurrence of from
in this string.
const string = 'Dart is fun';
print(string.replaceFirstMapped(
'fun', (m) => 'open source')); // Dart is open source
print(string.replaceFirstMapped(
RegExp(r'\w(\w*)'), (m) => '<${m[0]}-${m[1]}>')); // <Dart-art> is fun
Returns a new string, which is this string
except that the first match of from
, starting from startIndex
,
is replaced by the result of calling replace
with the match object.
The startIndex
must be non-negative and no greater than length.
Implementation
String? replaceFirstMapped(Pattern from, String replace(Match match),
[int startIndex = 0]) =>
value?.replaceFirstMapped(from, replace, startIndex);