Solved

/" in JavaScript

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript Case Expression 7 29
Angular - code works but need to make a change 14 30
https://github.com/willowsystems/jSignature 11 46
javascript comparing two dates 3 18
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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

805 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