programming-examples/js/String/Convert a string to title case.js
2019-11-15 12:59:38 +01:00

10 lines
365 B
JavaScript

function sentenceCase (str) {
if ((str===null) || (str===''))
return false;
else
str = str.toString();
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
console.log(sentenceCase('PHP exercises. python exercises.'));