0

If for a single capital word I know how to do that but for multiple capital word not sure how to do that.

single word: value.toLowerCase().charAt(0).toUpperCase() + value.toLowerCase().slice(1);

It will change "DONE" to "Done" But if I have "DONE DEAL" it changing to "Done deal" but it should like "Done Deal"

samnu pel
  • 914
  • 5
  • 12

2 Answers2

0

You should use split method in order to apply the rule for every work in sentence.

var str="done done";
console.log(str.split(' ').map(function(item){
  return item.toLowerCase().charAt(0).toUpperCase() + item.toLowerCase().slice(1);
}).join(' '))
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
0

Could do

    String line = "DONE DEAL";
    String[] words = line.split("\\s");
    for(String eachWord: words){
        String concat = eachWord.substring(0, 1).toUpperCase().concat(eachWord.substring(1).toLowerCase());
        System.out.println(concat);
    }
Emanuel Ramirez
  • 392
  • 2
  • 8