How to escape double quotes while concatenating a string? For example i hoped
(concatenate 'string "Mama said: " "\"Son, your life is an open book...\"")
to give:
"Mama said: "Son, your life is an open book...""
but instead returned it with backslashes as:
"Mama said: \"Son, your life is an open book...\""
“Double quotes 'escape' double quotes“ When using double quotes "" to create a string literal, the double quote character needs to be escaped using a backslash: \" .
' You can put a backslash character followed by a quote ( \" or \' ). This is called an escape sequence and Python will remove the backslash, and put just the quote in the string.
Use double quotation marks (“”) around a direct quote. A direct quote is a word- for-word report of what someone else said or wrote. You use the exact words and punctuation of the original. Harriet Jacobs writes, “She sat down, quivering in every limb” (61).
The returned value is printed readably, that is, using a representation that can be parsed with READ into a CL object. If you use a function like PRINC which prints a string as-is you will see that the quoting did what you wanted (the outer quotes are not part of the string):
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...\""
The first line is the result of PRINC, the second one of the PRINT part of the READ-EVAL-PRINT-LOOP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With