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


Groups > comp.lang.javascript > #37140

Re: string.replace()

From Martin Leese <please@see.Web.for.e-mail.INVALID>
Newsgroups comp.lang.javascript
Subject Re: string.replace()
Date 2019-08-14 15:36 -0600
Organization A noiseless patient Spider
Message-ID <qj1ut3$2u6$1@dont-email.me> (permalink)
References <qiv5ub$i5$1@dont-email.me> <dc4e4d48-dec0-4588-a8d6-1a25247e1f8c@googlegroups.com>

Show all headers | View raw


dr.j.r.stockton@gmail.com wrote:
> On Tuesday, 13 August 2019 21:18:26 UTC+1, Martin Leese  wrote:
>> I nice easy one to start the day.
>>
>> I wish to replace spaces in a string with
>> "+" characters.  I am using:
>>      var mungedTopic;
>>      mungedTopic.replace(/ /g, "+");
>>
>> but the spaces are not replaced.  There can
>> be multiple spaces, and I want to replace
>> them all.  I therefore need to use a regular
>> expression rather than a string.  I guess my
>> regular expression is wrong, but I don't see
>> why.
> 
> Method replace does not alter the pre-existing string, but returns an altered copy of it.
> 
> So :   mungedTopic = mungedTopic.replace(/ /g, "+");

Many thanks, that looks like it will work.
Can't test it at the moment; it is part of
an AJAX system, and the whole thing is down.

-- 
Regards,
Martin Leese
E-mail: please@see.Web.for.e-mail.INVALID
Web: http://members.tripod.com/martin_leese/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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