var myString = "{6} 123 Main St {7} Vancouver {7} CA {3}";
myString = myString.replace(/\{6\}/g,
Main Topics
Browse All Topics
string = "{6} 123 Main St {7} Vancouver CA {3}"
I have to find the {6} {7} {3} in the string and replace it with ' # ' ' , ' and ' ' (Hash,Comma,Space)
{6} = #
{7} = ,
{3} = ' '
That is whenever I find those numbers I have to replace them.
I did the following
string = "{6} 123 Main St {7} Vancouver CA {3}"
str = string.replace('{6}',"#");
This will show as "# 1234 Main St {7} Vancouver CA {3}"
How do I make it look like "# 123 Main St, Vancouver CA" in one sentence logic :)
If I do replace again for {7} and {3} in the abovwe string it works fine but when there are two {7} or {3} or {6} its replacing only one of the.
i,e if there are two {7} in a string it should replace two of them with ","(comma) not just one {7}
for eg: {6}4000{3} N Stemmons {7}Fwy{7} {3} Oregon {3} TX{3} 75084-8797 this should read as
#4000 N Stemmons ,Fwy, Oregon TX 75084-8797
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Or, if you want to do it all with one line of code:
function replaceAll( str, replacements ) {
for ( i = 0; i < replacements.length; i++ ) {
var idx = str.indexOf( replacements[i][0] );
while ( idx > -1 ) {
str = str.replace( replacements[i][0], replacements[i][1] );
idx = str.indexOf( replacements[i][0] );
}
}
return str;
}
var string = "{6} 123 Main St {7} Vancouver CA {3}";
string = replaceAll( string, [["{6}", "#"], [ "{7}", "," ],["{3}", " "]] );
alert( string );
-Mark
Business Accounts
Answer for Membership
by: mark-bPosted on 2004-05-04 at 11:52:34ID: 10989701
An example function:
function replaceAll( str, from, to ) {
var idx = str.indexOf( from );
while ( idx > -1 ) {
str = str.replace( from, to );
idx = str.indexOf( from );
}
return str;
}
var string = "{6} 123 Main St {7} Vancouver CA {3}";
string = replaceAll( string, "{6}", "#" );
string = replaceAll( string, "{7}", "," );
string = replaceAll( string, "{3}", " " );
alert( string );
-Mark