Skip to content

Instantly share code, notes, and snippets.

@pingbird
Created October 1, 2021 03:09
Show Gist options
  • Save pingbird/2ec00872219e1c215d1b7ed0ae87043d to your computer and use it in GitHub Desktop.
Save pingbird/2ec00872219e1c215d1b7ed0ae87043d to your computer and use it in GitHub Desktop.
String format(String formatString, Map<String, dynamic> vars) {
return formatString.replaceAllMapped(
RegExp(r'\$(\w+)'),
(name) => '${vars[name.group(1)]}',
);
}
void main() {
print(format(r'There are $count players', {'count': 123}));
print(format(r'$x + $y = $z', {'x': 9, 'y': 10, 'z': 21}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment