This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Quotes inside a string

4 posts · 1735 views

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

Escape the double-quote character with a backslash. Good luck.

Re: Quotes inside a string

meijin wrote: "Alfa "alfa" beta"
"Alfa \"alfa\" beta"

Re: Quotes inside a string

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.
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{"