Page 1 of 1

Quotes inside a string

Posted: Fri Jul 03, 2009 9:43 pm
by meijin
Hi,

I need to create a string that has quotes inside it. I would think this would be trivial, but I haven't been able to do it nor have I found any documentation on the topic. I basically need something like this:

"Alfa "alfa" beta"

where all of it is a string. I am trying to pass the whole string to a query.

~M

Re: Quotes inside a string

Posted: Mon Jul 06, 2009 5:56 pm
by chucks
Escape the double-quote character with a backslash. Good luck.

Re: Quotes inside a string

Posted: Mon Jul 06, 2009 8:32 pm
by dmitry_vk
meijin wrote: "Alfa "alfa" beta"

Code: Select all

"Alfa \"alfa\" beta"

Re: Quotes inside a string

Posted: Mon Jul 06, 2009 9:16 pm
by smithzv
There are actually some pretty clever tools out there that will help you with this as well. You could take a look at CL-INTERPOL (http://weitz.de/cl-interpol/) which, among other things, allows you to avoid having to escape quotes. It defines a reader syntax where you can use balanced delimiters like { and } to designate open and close of strings which fixes the entire issue of having to escape quotes (as long as the delimiters are balanced in the string). i.e.

Code: Select all

CL-USER> (asdf:oos 'asdf:load-op :cl-interpol)
; loading system definition from
; /Users/smithzv/dld/src/lisp-pkg/asdf/cl-interpol.asd into
; #<PACKAGE "ASDF0">
; registering #<SYSTEM #:CL-INTERPOL {129ECC49}> as CL-INTERPOL
NIL
CL-USER> (cl-interpol:enable-interpol-syntax)
; No value
CL-USER> #?{"}
"\""
CL-USER> #?{"monkey{"}}
"\"monkey{\"}"
CL-USER> #?[monkey{]
"monkey{"