Replace all strings


Ad

Advertisements

J

J.R.

How to replace all strings at the same time?

"ab,c,d"

If I understood correctly, you want to replace all the commas in a
variable with '', right? Then you might use a RegExp such as:

var a = "a,b,c,d";
a.replace(/,/g, '')
 
A

Archos

If I understood correctly, you want to replace all the commas in a
variable with '', right? Then you might use a RegExp such as:

var a = "a,b,c,d";
a.replace(/,/g, '')

Yes, thanks. I hope that the use of regular expressions been right for
main browsers.
 
E

Evertjan.

J.R. wrote on 22 feb 2012 in comp.lang.javascript:
If I understood correctly, you want to replace all the commas in a
variable with '', right? Then you might use a RegExp such as:

var a = "a,b,c,d";
a.replace(/,/g, '')

var a = "a,b,c,d";
a = a.replace(/,/g, '');

==============

If you don't feel comfortable with Regex, try:

var a = "a,b,c,d";
a = a.split(',').join('');
 
J

J.R.

Yes, thanks. I hope that the use of regular expressions been right for
main browsers.

Hi,
The "searchValue" argument of the String.prototype.replace method can be
a regular expression or not, according to the standards (ECMA-262
Editions 3 and 5, section 15.5.4.11).

Cheers,
Joao Rodrigues (J.R.)
 
Ad

Advertisements

G

Gene Wirchenko

On 22 Feb 2012 22:02:45 GMT, "Evertjan."

[snip]
If you don't feel comfortable with Regex, try:

var a = "a,b,c,d";
a = a.split(',').join('');

Neat! <added to arsenal>

Sincerely,

Gene Wirchenko
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top