toUpperFirst method

String toUpperFirst()

Converts the first letter of the string to uppercase and the rest to lowercase.

Example:

'hello world'.toUpperFirst() == 'Hello world'
'HELLO WORLD'.toUpperFirst() == 'Hello world'

Implementation

String toUpperFirst() {
  if (isEmpty) return this;

  return '${this[0].toUpperCase()}${substring(1).toLowerCase()}';
}