Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #37132
| Newsgroups | comp.lang.javascript |
|---|---|
| Subject | Re: string.replace() |
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
| References | <qiv5ub$i5$1@dont-email.me> <replace-20190814002416@ram.dialup.fu-berlin.de> |
| Date | 2019-08-14 10:18 +0200 |
| Message-ID | <XnsAAAB68E927159eejj99@194.109.6.166> (permalink) |
ram@zedat.fu-berlin.de (Stefan Ram) wrote on 14 Aug 2019 in comp.lang.javascript: > Martin Leese <please@see.Web.for.e-mail.INVALID> writes: >>mungedTopic.replace(/ /g, "+"); >>but the spaces are not replaced. > > main.js > > print( "True 1 1 0".replace( / /g, "+" )); > > transcript > > True+1+1+0 However, since there are other characters that produce a visible space, like the tab charater for instance, you possibly could prefer to use the \s for 'any spacelike character': myString = myString.replace( /\s/g, '+' )); ========================== If you are unsure about using Regex, replace() can also, in a simple way, be used without that: myString = myString.replace( ' ', '+' )); but then the /g for 'global' would not be there, and only the first instance of a space would be replaced. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
string.replace() Martin Leese <please@see.Web.for.e-mail.INVALID> - 2019-08-13 14:18 -0600
Re: string.replace() dr.j.r.stockton@gmail.com - 2019-08-13 14:52 -0700
Re: string.replace() Martin Leese <please@see.Web.for.e-mail.INVALID> - 2019-08-14 15:36 -0600
Re: string.replace() "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-08-14 10:18 +0200
Re: string.replace() Martin Leese <please@see.Web.for.e-mail.INVALID> - 2019-08-14 15:41 -0600
Re: string.replace() "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-08-15 13:55 +0200
csiph-web