Convert string to sentence case in javascript

前端 未结 10 656
别那么骄傲
别那么骄傲 2020-12-03 19:19

I want a string entered should be converted to sentence case in whatever case it is.

Like

hi all, this is derp. thank you all to answer my qu

10条回答
  •  不知归路
    2020-12-03 19:53

    On each line this script will print ..... Sunday Monday Tuesday Wednesday Thursday Friday Saturday.

    let rg = /(^\w{1}|\.\s*\w{1})/gi;
    
    const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
    
    for(let day of days) {
        console.log(day.replace(rg, function(toReplace) {
        return toReplace.toUpperCase();
    }))
    

提交回复
热议问题