|
|
||||
|
||||
|
|
|
|||
|
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.) |
|
|||
|
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. |
|
|||
|
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) |
|
|||
|
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.) |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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!)? |
|
|||
|
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> |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|