I have been looking through the Lisp 3rd edition and trying to find some way on the net... is there a way I can print the " character or store it as a part of the data in a string?
what I want to be able to do is ( " The man said "hello world" and went to his car. " ).
Is there some way to print a character code by code number?
*update
I actually later found the part of Lisp 3rd ed that covered this - it was buried in the Classes and Generic Functions chapter (c14, p191). Always the way when you are looking for somthing else the thing you were looking for first turns up.
how to print and store the " character in strings [SOLVED]
how to print and store the " character in strings [SOLVED]
Last edited by punchcard on Sun Oct 05, 2014 12:41 am, edited 1 time in total.
Re: how to print and store the " character in strings
The usual trick is the same as in most other programming langauges, just simply escape double-quotes with backslashes:
... or in FORMAT syntax:
This also works if you store the string in a variable:
In case of doubt see PRIN1, PRINC, and FORMAT.
Code: Select all
CL-USER> (princ "The man said \"hello world\" and went to his car.")
The man said "hello world" and went to his car. ; printed value using PRINC
"The man said \"hello world\" and went to his car." ; returned value
CL-USER> (prin1 "The man said \"hello world\" and went to his car.")
"The man said \"hello world\" and went to his car." ; printed value using PRIN1
"The man said \"hello world\" and went to his car." ; returned value
Code: Select all
CL-USER> (format t "~a~%" "The man said \"hello world\" and went to his car.")
The man said "hello world" and went to his car. ; printed value "~a"
NIL ; returned value
CL-USER> (format t "~s~%" "The man said \"hello world\" and went to his car.")
"The man said \"hello world\" and went to his car." ; printed value "~s"
NIL ; returned value
Code: Select all
CL-USER> (let ((my-string "The man said \"hello world\" and went to his car."))
(format t "~a~%" my-string)
(format t "~s~%" my-string))
The man said "hello world" and went to his car. ; printed value "~a"
"The man said \"hello world\" and went to his car." ; printed value "~s"
NIL ; returned value
Re: how to print and store the " character in strings
Thank you! thats great.