Created
March 15, 2023 11:43
-
-
Save Ankit-Slnk/3601db44c0f56746ab40dbfd1d16d9cd to your computer and use it in GitHub Desktop.
String extension toCapitalise and toTitlecase
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
extension StringCasingExtension on String { | |
String toCapitalized() => | |
length > 0 ? '${this[0].toUpperCase()}${substring(1).toLowerCase()}' : ''; | |
String toTitleCase() => replaceAll(RegExp(' +'), ' ') | |
.split(' ') | |
.map((str) => str.toCapitalized()) | |
.join(' '); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment