[Javascript] Escaping the PLUS SIGN

David Lovering dlovering at gazos.com
Sun Sep 14 23:09:09 CDT 2003


By general solution, I meant one in which the mapped character and the
substituted character were both variables.

-- Dave Lovering

----- Original Message ----- 
From: "innerlab.com" <info at innerlab.com>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Sunday, September 14, 2003 5:08 PM
Subject: Re: [Javascript] Escaping the PLUS SIGN


> ----- Original Message -----
> From: "David Lovering" <dlovering at gazos.com>
> Subject: Re: [Javascript] Escaping the PLUS SIGN
>
>
> > This isn't the most general solution, but how about
> >
> > var re = /\+/g;
> > var newstr = str.replace(re, "_");  // or whatever other character is
more
> > appropriate
> >
> > I just tested it, and it worked fine.
>
>
> It works fine. Thank you. Now, I'm curious about which one
> is the "most general solution".
>
>
>
>
>
> > ----- Original Message -----
> > From: "innerlab.com" <info at innerlab.com>
> > Subject: [Javascript] Escaping the PLUS SIGN
> >
> > > Hello:
> > >
> > > I am trying to replace plus signs in a string with another character,
> but
> > > I am getting a lot of errors. Below is a simple example in which a
text
> > > in a string is replaced by another:
> > >
> > > var str ="She sells sea shells by the sea";  // original string
> > >
> > > var strCut = "shells";  // text to be replaced by the one below
> > > var replStr = "food";  // text that replaces the one above
> > >
> > > // replacing actions
> > > var reg = new RegExp("\\b" + strCut + "\\b", "gi" )
> > > var newstr = str.replace(reg, replStr)
> > >
> > > //   output
> > > document.write(newstr)
> > >
> > > The original string becomes "She sells sea food by the sea"
> > >
> > > Now, how can I make the variable strCut be a plus sign?
> > >
> > > Thanks in advance
> > >
> > >
> > >
> > > _______________________________________________
> > > Javascript mailing list
> > > Javascript at LaTech.edu
> > > https://lists.LaTech.edu/mailman/listinfo/javascript
> > >
> > >
> >
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at LaTech.edu
> > https://lists.LaTech.edu/mailman/listinfo/javascript
> >
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>





More information about the Javascript mailing list