You are here: irt.org | BBS | Re: JavaScript 1.2 Challenge [This BBS is closed]
Posted by Vijay Jagdale on September 16, 1998 at 18:42:10:
In Reply to: Re: JavaScript 1.2 Challenge posted by Jason Nugent on September 04, 1998 at 10:00:46:
Cool Jason.. That will work. So will the code below. I was trying to use the power of Regular Expressions to make it do what I want in just one line of code, instead of 20. It sucks that "$1".toUpperCase () does not work when in theory it should.
Also from your code I noticed that you are using regular expression in the split () method. I didn't know we could do that.
Thanks
Vijay
<SCRIPT LANGUAGE="JavaScript1.2">
function initCap (inp){
re=/ ([A-Z]+)| ([^A-Z]+)/ig
a=inp.match (re)
if (a==null)
return inp;
outp=''
for (i=0;i<a.length;i++){
outp+= (i%2)==1?a[i]:a[i].charAt (0).toUpperCase ()+a[i].substring (1,a[i].length)
}
return outp
}
Follow-ups:
You are here: irt.org | BBS | Re: JavaScript 1.2 Challenge [This BBS is closed]