Date: 2009jun30
Language: javaScript
Q. How do make a string title case (first letter uppercase) in javaScript?
A.
function ucFirst(a) {
return a.substr(0,1).toUpperCase() + a.substr(1);
}
function titleCaseWord(a) {
return a.substr(0,1).toUpperCase() + a.substr(1).toLowerCase();
}
function titleCase(s) {
var title = '', a, word;
a = s.split(' ');
for (i = 0; i < a.length; i++) {
if (title != '') title += ' ';
title += titleCaseWord(a[i]);
}
return title;
}
| What this info useful to you? You can donate to say thanks |
Add a comment
Sign in to add a comment