Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Replace all strings

Reply
Thread Tools

Replace all strings

 
 
Archos
Guest
Posts: n/a
 
      02-22-2012
How to replace all strings at the same time?

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

"ab,c,d"
 
Reply With Quote
 
 
 
 
J.R.
Guest
Posts: n/a
 
      02-22-2012
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
 
 
 
 
Archos
Guest
Posts: n/a
 
      02-22-2012
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
 
Evertjan.
Guest
Posts: n/a
 
      02-22-2012
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
 
J.R.
Guest
Posts: n/a
 
      02-22-2012
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
 
Gene Wirchenko
Guest
Posts: n/a
 
      02-22-2012
On 22 Feb 2012 22:02:45 GMT, "Evertjan."
<> 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
 
 
 
Reply

Thread Tools

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to replace all strings matching a pattern with correspondinglower case strings ? anonym Java 1 01-15-2009 07:29 PM
pyrex functions to replace a method (Re: replace a method in class:how?) Brian Blais Python 1 06-27-2006 12:13 PM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
[perl-python] find & replace strings for all files in a dir Xah Lee Python 1 01-31-2005 11:10 PM
[perl-python] find & replace strings for all files in a dir Xah Lee Perl Misc 0 01-31-2005 08:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57