Uppercase first letter of variable

后端 未结 23 1385
粉色の甜心
粉色の甜心 2020-11-30 20:55

I have searched over the web can can\'t find anything to help me. I want to make the first letter of each word upper case within a variable.

So far i have tried:

23条回答
  •  一整个雨季
    2020-11-30 21:13

    You can try this simple code with the features of ucwords in PHP.

    function ucWords(text) {
        return text.split(' ').map((txt) => (txt.substring(0, 1).toUpperCase() + txt.substring(1, txt.length))).join(' ');
    }
    ucWords('hello WORLD');
    

    It will keep the Upper Cases unchanged.

提交回复
热议问题