2012-03-14 110 views
4

如何在連接字符串時轉義雙引號? 例如,我希望在Common Lisp中轉義雙引號

(concatenate 'string "Mama said: " "\"Son, your life is an open book...\"") 

,得到:

"Mama said: "Son, your life is an open book..."" 

而是與反斜線作爲返回它:

"Mama said: \"Son, your life is an open book...\"" 

回答

11

返回值被可讀地印刷,即,使用表示可以用READ將其解析爲CL對象。如果你使用像PRINC一個函數,它打印字符串,是你將看到引用沒有你想要的東西(外引號不是字符串的一部分):

CL-USER> (princ (concatenate 'string "Mama said: " "\"Son, your life is an open book...\"")) 
Mama said: "Son, your life is an open book..." 
"Mama said: \"Son, your life is an open book...\"" 

第一行的結果PRINC,READ-EVAL-PRINT-LOOP的PRINT部分的第二個部分。