Solved

/" in JavaScript

Posted on 2013-11-24
3
152 Views
Last Modified: 2013-12-13
In php if I want to store " I can use /" to tell php that it's not the string escape. Is there an equivalent in JavaScript?
0
Comment
Question by:tonelm54
3 Comments
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
ID: 39673313
in javascript you can use \".
However, please note that you can use this as an alternative:
string s1 = 'testing "quoted text" in a string variable';
string s2 = "testing \"quoted text\" in a string variable";

Open in new window

The s1 and s2 variables will contain exactly the same text.
The single quotes and double quotes are interchangeable. If you want to embed a double quote inside a string literal you can use single quotes on the outside
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39673315
I believe you mean \"
It's the same escape char in Javascript : \

var words = "He say \"Yes, I will do it !!!\"";

Open in new window

Or just use simple quote :
var words = 'He say "Yes, I will do it !!!"';

Open in new window

0
 
LVL 27

Expert Comment

by:tliotta
ID: 39676655
Be aware that if you "store" escaped characters, you might need to escape them again later. I.e., if you store an escaped character in a .properties file and retrieve it later, it can need to be re-escaped before it is stored again after, say, a change is made to that property. Handling strings that contain escaped characters can be tricky. I've seen it be a painful thing to fix.

Tom
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now