toTitleCase property
String?
toTitleCase
Returns the word title cased.
String foo = 'Hello dear friend how you doing ?';
Sting titleCased = foo.toTitleCase; // returns 'Hello Dear Friend How You Doing'.
Implementation
String? get toTitleCase {
if (this == null) return null;
if (this!.isEmpty) return this;
final words = this!.toLowerCase().split(' ');
for (var i = 0; i < words.length; i++) {
words[i] = words[i].substring(0, 1).toUpperCase() + words[i].substring(1);
}
return words.join(' ');
}