Created
March 4, 2024 16:54
-
-
Save luishendrix92/d732dedce032b99962133471a15bfb00 to your computer and use it in GitHub Desktop.
Title Case a String in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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