Jump to content

Javascript to parse a string without escaping characters


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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...