toCapitalize method

String toCapitalize()

Capitalizes the first letter of a string and converts the rest of the string to lowercase.

This extension method takes a string and capitalizes the first letter of the string while converting the rest of the string to lowercase. If the string is empty or only contains whitespace characters, the method returns the original string.

For example, the string "hELlo WoRLd" would be converted to "Hello world".

Returns the capitalized string.

Implementation

String toCapitalize() => this.isNotEmpty ? "${this[0].toUpperCase()}${substring(1).toLowerCase()}" : '';