titleCase method
Converts the string to title case, capitalizing the first letter and lowercasing the rest.
If the string is empty, it returns an empty string. The first character is a whole grapheme cluster, so a leading emoji or combining-mark cluster is kept intact.
Returns: A new string in title case, or an empty string if the original string is empty.
Example:
'mIxEd cAsE'.titleCase(); // Returns 'Mixed case'
'TITLE CASE'.titleCase(); // Returns 'Title case'
'👋AB'.titleCase(); // Returns '👋ab'
''.titleCase(); // Returns ''
Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
String titleCase() {
if (isEmpty) return '';
// Grapheme-safe split (see _splitFirstGrapheme) instead of this[0].
final (String first, String rest) = _splitFirstGrapheme(this);
return first.toUpperCase() + rest.toLowerCase();
}