Last active
January 27, 2021 01:35
-
-
Save ikhsanalatsary/64df9286554718438403da51029d570f to your computer and use it in GitHub Desktop.
Capitalize extension 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 _capitalize(String str) { | |
if (str == null) return ''; | |
if (str.length == 1) return str.toUpperCase(); | |
return '${str[0].toUpperCase() + str.substring(1)}'; | |
} | |
extension StringUtil on String { | |
String capitalize() { | |
return _capitalize(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment