toSentenceCase method

String toSentenceCase()

Converts the string to sentence case (e.g., "hello world" -> "Hello world").

Capitalizes the first letter of the string and keeps the rest unchanged.

Example:

"hello world".toSentenceCase(); // Returns "Hello world"
"".toSentenceCase(); // Returns ""

Implementation

String toSentenceCase() {
  if (isEmpty) return this;
  final trimmed = trim();
  return trimmed[0].toUpperCase() + trimmed.substring(1);
}