Uppercase first letter of variable

后端 未结 23 1489
粉色の甜心
粉色の甜心 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:09

    http://phpjs.org/functions/ucwords:569 has a good example

    function ucwords (str) {
        return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
            return $1.toUpperCase();
        });
    }
    

    (omitted function comment from source for brevity. please see linked source for details)

    EDIT: Please note that this function uppercases the first letter of each word (as your question asks) and not just the first letter of a string (as your question title asks)

提交回复
热议问题