W3cubDocs

/Dart 2

splitMapJoin method

String splitMapJoin (Pattern pattern, { String onMatch(Match match), String onNonMatch(String nonMatch) })

Splits the string, converts its parts, and combines them into a new string.

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 string is used.

Each non-matched part is converted by a call to onNonMatch. If onNonMatch is omitted, the non-matching part is used.

Then all the converted parts are combined into the resulting string.

'Eats shoots leaves'.splitMapJoin((new RegExp(r'shoots')),
    onMatch:    (m) => '${m.group(0)}',
    onNonMatch: (n) => '*'); // *shoots*

Implementation

String splitMapJoin(Pattern pattern,
    {String onMatch(Match match), String onNonMatch(String nonMatch)});

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-core/String/splitMapJoin.html