titleCase static method

String titleCase(
  1. String input
)

Convert the String to title case

Example:

String titleCased = GetStringUtils.titleCase("hello world");
// Result: "Hello World"

Implementation

static String titleCase(String input) {
  if (input.isEmpty) return input;

  return input.split(' ').map((word) {
    if (word.isEmpty) return word;

    return word[0].toUpperCase() + word.substring(1).toLowerCase();
  }).join(' ');
}