toPascalCase property
String
get
toPascalCase
Capitalizes the first letter of each word in the string.
- This method splits the string by spaces, hyphens, or underscores and capitalizes the first letter of each word while making the rest of the letters lowercase.
- Returns a new string where each word's first letter is capitalized, and the rest of the word is in lowercase.
Example:
"hello world".toPascalCase; // Returns "HelloWorld"
Returns: A String with the first letter of each word capitalized.
Implementation
String get toPascalCase {
return split(RegExp(r'[\s_-]+')).map((word) {
if (word.isEmpty) return word;
return word[0].toUpperCase() + word.substring(1).toLowerCase();
}).join('');
}