[Javascript] Re: Escaping the PLUS SIGN

Lewis Shadoff lshadoff at brazosport.cc.tx.us
Sun Sep 14 13:23:57 CDT 2003


Use the character encoding for the plus sign:  strCut = "+";

http://www.asciitable.com/

Lew


At 12:00 PM 9/14/2003, innerlab.com wrote:
>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

Lewis A. Shadoff, Ph.D.
Brazosport College
Lake Jackson, TX 





More information about the Javascript mailing list