Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Escape a double quote in a string

Status
Not open for further replies.

KingSlick

Programmer
Mar 9, 2007
45
US
Hello,

I am trying to escape a double quote character (") in a string. For example,

Code:
strQuote = "Scott said "Hello World. It's Mine" to everyone"

I also need to have a single quote within the same string.

Thanks in advance
-Scott
 
Use square brackets:

strQuote = [Scott said "Hello World. It's Mine" to everyone]
 
The single quote and double quote are handled within a string as distinctly different types.

Single quotes can appear within a double quote string and vice versa.

Code:
cTestString1 = "Scott said 'Hello World. It's Mine' to everyone"
?cTestString1

* --- Or ---
cTestString2 = 'Scott said "Hello World. It's Mine" to everyone'
?cTestString2

Good Luck,
JRB-Bldr
 
jrbbldr,
Trying to assign cTestString2 would give a syntax error, because of the apostrophe in [It's]
 
You are correct. I missed that one.

It souhld have been...
Code:
cTestString2 = 'Scott said "Hello World. It' + "'" + 's Mine" to everyone'
?cTestString2

Good Luck,
JRB-Bldr
 
Thanks for all the help. I think the best way is to use the chr(34).

-SM
 
It's always good to keep in mind that while VFP allows for 3 ways to nest or encapsulate quotes and text (double quotes, single quotes and square brackets), other languages were not designed to be so flexible. Some will work in certain formats and commands only with single quotes, sometimes only with double quotes. So as a general comment, keep that in mind if you're sending data back and forth between languages.
 
dbMark,

Hmm. Not sure I agree with that. Delimiters are used to delimit literal values in source code. Can't see how that affects the sending of data to "other languages" (other applications?).

Am I missing something?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
While I haven't been doing much web code recently, in the past I would build pages using VFP and I had to be very careful whether I used single quotes or double quotes or how I nested them in certain code. It was either HTML, VBScript or JavaScript, can't remember offhand which it was now, that in one specific usage required one delimiter type and not the other.

My purpose was just to note that this was another case where what works in VFP doesn't always work elsewhere.

I admit I could have been going off on a tangent a bit. It reminds me of the PBS series "Connections" in the 1980s. The narrator led the viewer using a cascade of seemingly unconnected events and techniques from the Roman Empire to modern day showing that until one or several inventions or discoveries were made, the next ones weren't possible.
 
My purpose was just to note that this was another case where what works in VFP doesn't always work elsewhere.

Can't argue with that. I did a couple of weeks work in PHP earlier this year. When I went back to VFP, it took an effort to stop putting semi-colons at the end of every line.

But I'm not sure if that's a reason to prefer one type of delimiter over another.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top