CamelCase in Dart
Example for versions
Dart 1.1.1
splitMapJoin
splits the string into parts that match the pattern and parts that don’t match it, converts each part using corresponding function (in this case capitalizes matches and removes non-matches), and combines the results into a new string.
import 'dart:io';
main() {
String text = stdin.readLineSync().toLowerCase();
String capitalize(Match m) => m[0].substring(0, 1).toUpperCase() + m[0].substring(1);
String skip(String s) => "";
print(text.splitMapJoin(new RegExp(r'[a-z]+'), onMatch: capitalize, onNonMatch: skip));
}
Comments
]]>blog comments powered by Disqus
]]>