toCapitalizedWithSpace method
Converts the string to title case with spaces.
HelloWorld -> Hello World
Implementation
String toCapitalizedWithSpace() {
RegExp regExp = RegExp('[A-Z]');
String string = toTitleCase();
List<int> matches = regExp.allMatches(string).map((e) => e.start).toList();
return string.splitMapJoin(regExp, onMatch: ((match) {
String str = match.input.substring(match.start, match.end);
if (matches.indexOf(match.start) == 0) {
return str;
} else {
return ' ${str.toLowerCase()}';
}
}));
}