Jump to content

Javascript to parse a string without escaping characters


bosoxbill

Recommended Posts

How can I get Javascript to see a block of text as literal text without having to escape characters? I need to load a block of text and do multiple searches and replacements, but I'm going to get errors if the block of text has characters that need to be escaped that I don't know about. Is this possible and if not, what programming language should I use?

Link to comment
Share on other sites

If you're talking about printing a string of text as a Javascript variable then you need to escape quotes, newlines, and slashes. Otherwise, you can load it from an external source like a text file or database. It's easy enough to add slashes before characters that need them, but it's hard to suggest a solution without knowing exactly what you're trying to do.

Link to comment
Share on other sites

You can use Javascript to load the text file via ajax as long as it is on the same domain. You don't need to escape anything if you're saving the response from the ajax call in a Javascript variable (it will already be in a variable, actually).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...