Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #12053 > unrolled thread

Replace all strings

Started byArchos <raul.san@sent.com>
First post2012-02-22 09:48 -0800
Last post2012-02-22 15:03 -0800
Articles 9 — 6 participants

Back to article view | Back to comp.lang.javascript


Contents

  Replace all strings Archos <raul.san@sent.com> - 2012-02-22 09:48 -0800
    Re: Replace all strings "J.R." <groups_jr-1@yahoo.com.br> - 2012-02-22 16:48 -0200
      Re: Replace all strings Archos <raul.san@sent.com> - 2012-02-22 11:29 -0800
        Re: Replace all strings "J.R." <groups_jr-1@yahoo.com.br> - 2012-02-22 20:27 -0200
          Re: Replace all strings Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-23 14:36 +0100
            Re: Replace all strings Captain Paralytic <paul_lautman@yahoo.com> - 2012-02-23 05:55 -0800
              Re: Replace all strings Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-23 15:12 +0100
      Re: Replace all strings "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-22 22:02 +0000
        Re: Replace all strings Gene Wirchenko <genew@ocis.net> - 2012-02-22 15:03 -0800

#12053 — Replace all strings

FromArchos <raul.san@sent.com>
Date2012-02-22 09:48 -0800
SubjectReplace all strings
Message-ID<f65a4c81-b021-4254-b8d3-725858e39f32@vh10g2000pbc.googlegroups.com>
How to replace all strings at the same time?

>>> var a = "a,b,c,d";
>>> a.toString().replace(",", "")
"ab,c,d"

[toc] | [next] | [standalone]


#12063

From"J.R." <groups_jr-1@yahoo.com.br>
Date2012-02-22 16:48 -0200
Message-ID<ji3d9u$l9r$1@speranza.aioe.org>
In reply to#12053
On 22/02/2012 15:48, Archos wrote:
> How to replace all strings at the same time?
>
>>>> var a = "a,b,c,d";
>>>> a.toString().replace(",", "")
> "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, '')

-- 
Joao Rodrigues (J.R.)

[toc] | [prev] | [next] | [standalone]


#12066

FromArchos <raul.san@sent.com>
Date2012-02-22 11:29 -0800
Message-ID<0794f674-e437-4d95-87b3-f1580418f1fb@sk8g2000pbc.googlegroups.com>
In reply to#12063
On Feb 22, 6:48 pm, "J.R." <groups_j...@yahoo.com.br> wrote:
> On 22/02/2012 15:48, Archos wrote:
>
> > How to replace all strings at the same time?
>
> >>>> var a = "a,b,c,d";
> >>>> a.toString().replace(",", "")
> > "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, '')
>
> --
> Joao Rodrigues (J.R.)

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

[toc] | [prev] | [next] | [standalone]


#12069

From"J.R." <groups_jr-1@yahoo.com.br>
Date2012-02-22 20:27 -0200
Message-ID<ji3q58$nr6$1@speranza.aioe.org>
In reply to#12066
On 22/02/2012 17:29, Archos wrote:
> On Feb 22, 6:48 pm, "J.R."<groups_j...@yahoo.com.br>  wrote:
>> On 22/02/2012 15:48, Archos wrote:
>>
>>> How to replace all strings at the same time?
>>
>>>>>> var a = "a,b,c,d";
>>>>>> a.toString().replace(",", "")
>>> "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, '')
>>
>
> 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.)

[toc] | [prev] | [next] | [standalone]


#12091

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-02-23 14:36 +0100
Message-ID<1938247.aqSPkdTlGX@PointedEars.de>
In reply to#12069
J.R. wrote:

> On 22/02/2012 17:29, Archos wrote:
>> On Feb 22, 6:48 pm, "J.R."<groups_j...@yahoo.com.br>  wrote:
>>> On 22/02/2012 15:48, Archos wrote:
>>>> How to replace all strings at the same time?
>>>>>>> var a = "a,b,c,d";
>>>>>>> a.toString().replace(",", "")
>>>> "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, '')
>> Yes, thanks. I hope that the use of regular expressions been right for
>> main browsers.
> 
> 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).

More importantly, the RegExp initialiser (sic!) and constructor are 
supported since at least JScript 5.5.6330 (IE 5.5), JavaScript 1.5 
(NN6/Fx1), V8 3.6.6.19 (Cr16), JavaScriptCore 531.22.7 (Safari 4.0.5),
Opera ECMAScript 7.02, KDE JavaScript 4.6.5 (Konqueror 4.6.5).


PointedEars
-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

[toc] | [prev] | [next] | [standalone]


#12093

FromCaptain Paralytic <paul_lautman@yahoo.com>
Date2012-02-23 05:55 -0800
Message-ID<4c594bd3-157d-4d25-8fe0-b16af3e15249@f14g2000yqe.googlegroups.com>
In reply to#12091
On Feb 23, 1:36 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
> J.R. wrote:
> > On 22/02/2012 17:29, Archos wrote:
> >> On Feb 22, 6:48 pm, "J.R."<groups_j...@yahoo.com.br>  wrote:
> >>> On 22/02/2012 15:48, Archos wrote:
> >>>> How to replace all strings at the same time?
> >>>>>>> var a = "a,b,c,d";
> >>>>>>> a.toString().replace(",", "")
> >>>> "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, '')
> >> Yes, thanks. I hope that the use of regular expressions been right for
> >> main browsers.
>
> > 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).
>
> More importantly, the RegExp initialiser (sic!) and constructor are

Why the (sic!)?

[toc] | [prev] | [next] | [standalone]


#12097

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-02-23 15:12 +0100
Message-ID<22171861.ikSu5bs1Z4@PointedEars.de>
In reply to#12093
Captain Paralytic wrote:

> Thomas 'PointedEars' Lahn wrote:
>> J.R. wrote:
>> > On 22/02/2012 17:29, Archos wrote:
>> >> On Feb 22, 6:48 pm, "J.R."<groups_j...@yahoo.com.br>  wrote:
>> >>> var a = "a,b,c,d";
>> >>> a.replace(/,/g, '')
>> >> Yes, thanks. I hope that the use of regular expressions been right for
>> >> main browsers.
>> >
>> > 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).
>>
>> More importantly, the RegExp initialiser (sic!) and constructor are
> 
> Why the (sic!)?

Because I try to use American English on the Net, but the ECMAScript 
Language Specification uses British English there (probably because it is 
published by Ecma International based in Geneva).

However, your question has made me look it up again.  The correct terms are 
"Regular Expression *Literal*" (ECMA-262 5.1 Ed., section 7.8.5), "Array 
Initialiser" (11.1.4) and "Object Initialiser" (11.1.5).  Thanks.


PointedEars
-- 
Sometimes, what you learn is wrong. If those wrong ideas are close to the 
root of the knowledge tree you build on a particular subject, pruning the 
bad branches can sometimes cause the whole tree to collapse.
  -- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>

[toc] | [prev] | [next] | [standalone]


#12068

From"Evertjan." <exjxw.hannivoort@interxnl.net>
Date2012-02-22 22:02 +0000
Message-ID<XnsA001EA6E237E3eejj99@194.109.133.133>
In reply to#12063
J.R. wrote on 22 feb 2012 in comp.lang.javascript:

> On 22/02/2012 15:48, Archos wrote:
>> How to replace all strings at the same time?
>>
>>>>> var a = "a,b,c,d";
>>>>> a.toString().replace(",", "")
>> "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, '')
> 

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.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#12072

FromGene Wirchenko <genew@ocis.net>
Date2012-02-22 15:03 -0800
Message-ID<e0tak712i2416bl4b32qd5gtf2f6p4d6no@4ax.com>
In reply to#12068
On 22 Feb 2012 22:02:45 GMT, "Evertjan."
<exjxw.hannivoort@interxnl.net> wrote:

[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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web