Quotes inside a string

Discussion of Common Lisp

Quotes inside a string

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

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
meijin
 

Re: Quotes inside a string

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

Escape the double-quote character with a backslash. Good luck.
chucks
 
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"
dmitry_vk
 
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
; #<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{"
smithzv
 
Posts: 94
Joined: Wed Jul 23, 2008 11:36 am


Return to Common Lisp

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron