![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #2 |
|
Regular Coder ![]() Join Date: Mar 2006
Posts: 346
Thanks: 7
Thanked 45 Times in 44 Posts
![]() |
/* You oughta be able to cut it out of this function-
it capitalizes a string, or each word in a string. */ Code:
String.prototype.capit= function(deep){
var str= this.toLowerCase();
var Rx= deep? /\b([a-z']+)\b/g: /\b([a-z]+)\b/;
str= str.replace(Rx, function(w){
return w.charAt(0).toUpperCase()+ w.substring(1);
});
return str;
}
alert(s.capit()+'\n'+s.capit(true)) Last edited by mrhoo; 06-10-2009 at 03:46 PM.. |
|
|
|
|
|
PM User | #3 |
|
Master Coder ![]() Join Date: Jun 2002
Location: London, England
Posts: 7,083
Thanks: 85
Thanked 834 Times in 815 Posts
![]() ![]() |
Another (slightly simpler) method or variation:-
Code:
var str = "jEAn-paul o'flaNAGan-macDONald is a good guy."
str = str.toLowerCase().replace(/\b[a-z]/g,function(w){return w.toUpperCase()});
alert(str);
Looking for a pen? Look no further than Pen Island: www.penisland.net |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Rate This Thread | |
|
|