Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.java.* > Newsgroup comp.lang.javascript

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-22-2012, 04:48 PM
Archos
Guest
 
Posts: n/a
Default Replace all strings

How to replace all strings at the same time?

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

"ab,c,d"
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 02-22-2012, 05:48 PM
J.R.
Guest
 
Posts: n/a
Default Re: Replace all strings

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.)
Reply With Quote
  #3 (permalink)  
Old 02-22-2012, 06:29 PM
Archos
Guest
 
Posts: n/a
Default Re: Replace all strings

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.
Reply With Quote
  #4 (permalink)  
Old 02-22-2012, 09:02 PM
Evertjan.
Guest
 
Posts: n/a
Default Re: Replace all strings

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)
Reply With Quote
  #5 (permalink)  
Old 02-22-2012, 09:27 PM
J.R.
Guest
 
Posts: n/a
Default Re: Replace all strings

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.)
Reply With Quote
  #6 (permalink)  
Old 02-22-2012, 10:03 PM
Gene Wirchenko
Guest
 
Posts: n/a
Default Re: Replace all strings

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
Reply With Quote
  #7 (permalink)  
Old 02-23-2012, 12:36 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: Replace all strings

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
Reply With Quote
  #8 (permalink)  
Old 02-23-2012, 12:55 PM
Captain Paralytic
Guest
 
Posts: n/a
Default Re: Replace all strings

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!)?
Reply With Quote
  #9 (permalink)  
Old 02-23-2012, 01:12 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: Replace all strings

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>
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 06:09 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.