Replace all strings

Discussion in 'Javascript' started by Archos, Feb 22, 2012.

  1. Archos

    Archos Guest

    How to replace all strings at the same time?
    Archos, Feb 22, 2012
    1. Advertisements

  2. Archos

    J.R. Guest

    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, '')
    J.R., Feb 22, 2012
    1. Advertisements

  3. Archos

    Archos Guest

    Yes, thanks. I hope that the use of regular expressions been right for
    main browsers.
    Archos, Feb 22, 2012
  4. Archos

    Evertjan. Guest

    J.R. wrote on 22 feb 2012 in comp.lang.javascript:
    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('');
    Evertjan., Feb 22, 2012
  5. Archos

    J.R. Guest

    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

    Joao Rodrigues (J.R.)
    J.R., Feb 22, 2012
  6. On 22 Feb 2012 22:02:45 GMT, "Evertjan."

    Neat! <added to arsenal>


    Gene Wirchenko
    Gene Wirchenko, Feb 22, 2012
    1. 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 (here). After that, you can post your question and our members will help you out.