Quotes inside a string

Discussion of Common Lisp

Quotes inside a string

Postby meijin » Fri Jul 03, 2009 9:43 pm


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.


Re: Quotes inside a string

Postby chucks » Mon Jul 06, 2009 5:56 pm

Escape the double-quote character with a backslash. Good luck.
Posts: 6
Joined: Thu Sep 18, 2008 4:12 pm

Re: Quotes inside a string

Postby dmitry_vk » Mon Jul 06, 2009 8:32 pm

meijin wrote:"Alfa "alfa" beta"

Code: Select all
"Alfa \"alfa\" beta"
Posts: 96
Joined: Sat Jun 28, 2008 8:01 am
Location: Russia, Kazan

Re: Quotes inside a string

Postby smithzv » Mon Jul 06, 2009 9:16 pm

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
; registering #<SYSTEM #:CL-INTERPOL {129ECC49}> as CL-INTERPOL
CL-USER> (cl-interpol:enable-interpol-syntax)
; No value
CL-USER> #?{"}
CL-USER> #?{"monkey{"}}
CL-USER> #?[monkey{]
Posts: 94
Joined: Wed Jul 23, 2008 11:36 am

Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 8 guests