removeUnderscoreAndCapitalize method

String removeUnderscoreAndCapitalize()

Implementation

String removeUnderscoreAndCapitalize() {
  List<String> refactoredString = [];
  List<String> wordList = [];
  if (isNotEmpty) {
    wordList = toLowerCase().replaceAll('_', ' ').split(' ');
  }
  if (wordList.isEmpty) {
    return capitalize();
  }
  for (int i = 0; i < wordList.length; i++) {
    refactoredString.add(
      ((i == 0) ? wordList[i][0].toUpperCase() : wordList[i][0]) +
          wordList[i].substring(1),
    );
  }
  return wordList.isEmpty ? this : refactoredString.join(" ");
}