
04-12-2006, 10:07 AM
|
|
Web Hosting Evangelist
|
|
Join Date: Dec 2005
Posts: 549
|
|
Javascript: How to replace first character in String?
what's the equivalent of $string{0} = $replacement in Javascript?
|

04-12-2006, 10:50 AM
|
|
Web Hosting Guru
|
|
Join Date: May 2004
Location: Singapore
Posts: 262
|
|
__________________
#include<cstdio>
char*s="#include<cstdio>%cchar*s=%c%s%c;%cint main(){std::printf(s,10,34,s,34,10);}";
int main(){std::printf(s,10,34,s,34,10);}
|

04-12-2006, 11:26 AM
|
|
Web Hosting Master
|
|
Join Date: Mar 2004
Posts: 1,301
|
|
how about:
oldStr = new String("fun");
newStr= oldStr.replace(oldStr.charAt(0), "s");
|

04-12-2006, 11:30 AM
|
|
Junior Guru Wannabe
|
|
Join Date: Apr 2005
Posts: 33
|
|
var str="Hello world!"
var oldstr=str.substring(1);
var newfirstletter="Z";
var newstr=newfirstletter+oldstr;
|

04-12-2006, 11:34 AM
|
|
Junior Guru Wannabe
|
|
Join Date: Apr 2005
Posts: 33
|
|
Quote:
|
Originally Posted by orbitz
how about:
oldStr = new String("fun");
newStr= oldStr.replace(oldStr.charAt(0), "s");
|
Guess what would happen if the string had more than one 'f' in it?
|

04-12-2006, 11:57 AM
|
|
Web Hosting Master
|
|
Join Date: Mar 2004
Posts: 1,301
|
|
|

04-12-2006, 11:59 AM
|
|
Web Hosting Guru
|
|
Join Date: May 2004
Location: Singapore
Posts: 262
|
|
Nah, I think mine is wrong. Havent worked with Javascript for quite a while, heh.
It should just be:
Code:
str = ch + str.substring(1);
which is pretty much your idea, jabab.
__________________
#include<cstdio>
char*s="#include<cstdio>%cchar*s=%c%s%c;%cint main(){std::printf(s,10,34,s,34,10);}";
int main(){std::printf(s,10,34,s,34,10);}
|

04-12-2006, 12:02 PM
|
|
Web Hosting Master
|
|
Join Date: Mar 2004
Posts: 1,301
|
|
replace function can do a whole lot more than just substring and concatenation
have you checked out the replace function i posted above

|

04-12-2006, 12:14 PM
|
|
Junior Guru Wannabe
|
|
Join Date: Apr 2005
Posts: 33
|
|
Didn't think that would happen 
|

04-12-2006, 04:58 PM
|
|
Web Hosting Evangelist
|
|
Join Date: Dec 2005
Posts: 549
|
|
ah. it's time like this that you start to appreciate php's built-in library of functions.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|