Solved

/" in JavaScript

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

685 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