473,320 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Reliable replace function?

Hello,
Can anyone recommend a good Javascript cross-browser string replace
method? On both PC Mozilla Firefox and IE 6, I tried this

var str = requiredField.replace("_", " ");

where requiredField = "Ship_To_First_Name", but sadly the value of str
was "Ship To_First_Name". It seemed only one "_" had been replaced.

Thanks for any advice, - Dave
Jul 23 '05 #1
2 1150
Lee
D. Alvarado said:

Hello,
Can anyone recommend a good Javascript cross-browser string replace
method? On both PC Mozilla Firefox and IE 6, I tried this

var str = requiredField.replace("_", " ");

where requiredField = "Ship_To_First_Name", but sadly the value of str
was "Ship To_First_Name". It seemed only one "_" had been replaced.


You used a correct and reliable method, you simply failed to read the
documentation. If you pass a RegExp object as the first argument, you
can specify the "global replacement" switch:

var str = requiredField.replace(/_/g, " ");

Jul 23 '05 #2
D. Alvarado wrote:
var str = requiredField.replace("_", " ");

where requiredField = "Ship_To_First_Name", but sadly the value of str
was "Ship To_First_Name". It seemed only one "_" had been replaced.


Works as designed.

var str = requiredField.replace(/_/g, " ");

RTFM.
PointedEars
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Danny | last post by:
I need an asp command to strip out from a string all extra punctuation such as apostrophe, comma, period, spaces dashes, etc etc and just leave the letters. Can anybody give me some ideas? ...
0
by: WebM¤nkey | last post by:
Hey Guys I am using the WebRequest class to do a http post and recieve a response back. As my application talks to another server for authentication etc this is the only way. But for some reason...
8
by: Matt Kruse | last post by:
I've found that under some circumstances, some code that I've been using to find an object's coordinates with respect to the viewport does not behave correctly. Is there a function that has been...
0
by: Gabriel Genellina | last post by:
En Sun, 20 Apr 2008 10:32:36 -0300, Banibrata Dutta <banibrata.dutta@gmail.comescribió: Because *any* string can be used to retrieve an attribute, it is not easy to replace *every* occurence of...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.