splitMapJoin method Null safety

String splitMapJoin (
  1. Pattern pattern,
  2. {String onMatch(
    1. Match
    ),
  3. String onNonMatch(
    1. String
    )}
)

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});