splitMapJoin method Null safety
Splits the string, converts its parts, and combines them into a new string.
The pattern
is used to split the string
into parts and separating matches.
Each match is converted to a string by calling onMatch
. If onMatch
is omitted, the matched substring is used.
Each non-matched part is converted by a call to onNonMatch
. If
onNonMatch
is omitted, the non-matching substring is used.
Then all the converted parts are combined into the resulting string.
'Eats shoots leaves'.splitMapJoin((RegExp(r'shoots')),
onMatch: (m) => '${m[0]!}', // or no onMatch at all
onNonMatch: (n) => '*'); // *shoots*
Implementation
String splitMapJoin(Pattern pattern,
{String Function(Match)? onMatch, String Function(String)? onNonMatch});