hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Javascript: How to replace first character in String?
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Javascript: How to replace first character in String?

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 04-12-2006, 10:07 AM
grabmail grabmail is offline
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?

Reply With Quote


Sponsored Links
  #2  
Old 04-12-2006, 10:50 AM
laserlight laserlight is offline
Web Hosting Guru
 
Join Date: May 2004
Location: Singapore
Posts: 262
Perhaps str[0] = ch?

__________________
#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);}

Reply With Quote
  #3  
Old 04-12-2006, 11:26 AM
orbitz orbitz is offline
Web Hosting Master
 
Join Date: Mar 2004
Posts: 1,301
how about:

oldStr = new String("fun");
newStr= oldStr.replace(oldStr.charAt(0), "s");

Reply With Quote
Sponsored Links
  #4  
Old 04-12-2006, 11:30 AM
jabab jabab is offline
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;

Reply With Quote
  #5  
Old 04-12-2006, 11:34 AM
jabab jabab is offline
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?

Reply With Quote
  #6  
Old 04-12-2006, 11:57 AM
orbitz orbitz is offline
Web Hosting Master
 
Join Date: Mar 2004
Posts: 1,301
don't guess. try it!

Reply With Quote
  #7  
Old 04-12-2006, 11:59 AM
laserlight laserlight is offline
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);}

Reply With Quote
  #8  
Old 04-12-2006, 12:02 PM
orbitz orbitz is offline
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

Reply With Quote
  #9  
Old 04-12-2006, 12:14 PM
jabab jabab is offline
Junior Guru Wannabe
 
Join Date: Apr 2005
Posts: 33
Didn't think that would happen

Reply With Quote
  #10  
Old 04-12-2006, 04:58 PM
grabmail grabmail is offline
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.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
eNom Readies One and Two-Character .ORG Domain Auction Web Hosting News 2013-04-01 13:31:57
Web Host Hostway Replaces Legacy Webmail with Open-Xchange Web Hosting News 2013-02-01 11:17:40
.CA Domain Will Support French Characters Starting Mid-January Web Hosting News 2012-12-31 15:11:30
ICANN 45: New gTLD Overview and Information for Applicants with ICANN CSO Kurt Pritz Web Hosting News 2012-10-15 14:01:26
Colocation Firm Mac Mini Vault Uses Apple TV as Web Server in 24-Hour Experiment Web Hosting News 2011-05-20 19:57:22


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?