Skip to content

Instantly share code, notes, and snippets.

@luishendrix92
Created March 4, 2024 16:54
Show Gist options
  • Save luishendrix92/d732dedce032b99962133471a15bfb00 to your computer and use it in GitHub Desktop.
Save luishendrix92/d732dedce032b99962133471a15bfb00 to your computer and use it in GitHub Desktop.
Title Case a String in Dart
String titleCase(String input) {
return input.splitMapJoin(RegExp(r'(\s+|\[|\(|\/)+'),
onMatch: (m) => '${m[0]}',
onNonMatch: (word) {
if (word.length < 2) return word.toUpperCase();
return word.substring(0, 1).toUpperCase() + word.substring(1);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment