capitalize method

String capitalize()

Capitalizes the first letter of the string.

Returns the original string if empty.

Example:

'hello'.capitalize(); // 'Hello'
'HELLO'.capitalize(); // 'HELLO' (first letter only)

Implementation

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