Solved

/" in JavaScript

Posted on 2013-11-24
3
153 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

863 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

19 Experts available now in Live!

Get 1:1 Help Now