toSentenceCase method

  1. @useResult
String toSentenceCase([
  1. Pattern? separators
])

Sentence-cases this string.

wordSeparators is used to separate words if separators is not given.

'camelCase'.toSentenceCase(); // 'Camel case'

'PascalCase'.toSentenceCase(); // 'Pascal case'

'SCREAMING_CASE'.toSentenceCase(); // 'Screaming case'

'documenting HTML code'.toTitleCase(); // 'Documenting HTML code'

'snake_case'.toSentenceCase(); // 'Snake case'

'kebab case'.toSentenceCase(); // 'Kebab case'

'Title Case'.toSentenceCase(); // 'Title case'

'Sentence case'.toSentenceCase(); // 'Sentence case'

Implementation

@useResult String toSentenceCase([Pattern? separators]) => split(separators ?? wordSeparators)
    .where((e) => e.isNotEmpty)
    .map((e) => e.isUpperCase ? e : e.toLowerCase())
    .join(' ')
    .capitalize();