[thelist] [JavaScript] Avoid Escaping Characters

Hershel Robinson hershelr at netvision.net.il
Mon May 24 10:25:35 CDT 2004


>> Some languages have a method to define a string literal wherein what
>> would normally be an escape character is not treated as such, rather
>> the escape character is taken literally. So \n would be two
>> characters, not one special one.

> I haven't tried this, but did you try "\\n"?  (where "\\"
> should escape the "\" and display it as a \)

You are correct that \\n indeed is parsed by JS as two characters, a
blackslash and an en. This is not what my question was, however. My question
was how to parse \n itself as two characters and not one.

The one solution (it's a solution to my actual problem, not a solution to
question I actually asked) is to put the string in question into a hidden
input and then access its value. Using such a method, no escape characters
will be found and \n comes out as two characters.

Hershel



More information about the thelist mailing list