Code Red > AutoLISP (Vanilla / Visual)

How to Add Double Quotes in A Message

(1/2) > >>

MeasureUp:
Sorry I have not wrote codes for a long time.
Here is my question and below is a simplified case.
I'd like to show a message after user input:

--- Code: ---(setq UserInput (getstring "Enter Letters: "))
(strcat "Your Input is " ... UserInput ... ".")

--- End code ---

The message should be shown as below if the input was ABC.

--- Quote ---Your Input is "ABC".

--- End quote ---

Your helps are much appreciated.

kpblc:

--- Code - Auto/Visual Lisp: ---(strcat "Your Inout is \"" UserInput "\".")

Lee Mac:
FWIW, you can determine the required escape characters by evaluating (getstring) at the AutoCAD command-line and entering the string that you wish to display - getstring will then return the string with the appropriate escape characters inserted for correct representation in AutoLISP, e.g.:

--- Code: ---Command: (getstring t "\nEnter string: ")
Enter string: Your input is "ABC"
"Your input is \"ABC\""
--- End code ---

MeasureUp:
Thanks to kpblc & Lee.
And Lee, you are too smart as always. :laugh: It is a good idea.
My confusion is the resault I got.

--- Quote ---"Your input is \"ABC\"."

--- End quote ---
But when "princ" is added it shows correctly at command line.

--- Code: ---(princ (strcat "Your Input is \"" UserInput "\"."))

--- End code ---

--- Quote ---Your input is "ABC".

--- End quote ---

Lee Mac:

--- Quote from: MeasureUp on June 11, 2019, 07:18:23 PM ---My confusion is the resault I got.

--- Quote ---"Your input is \"ABC\"."

--- End quote ---
But when "princ" is added it shows correctly at command line.

--- Code: ---(princ (strcat "Your Input is \"" UserInput "\"."))

--- End code ---

--- Quote ---Your input is "ABC".

--- End quote ---

--- End quote ---

This is because ordinarily the double-quote character represents a string delimiter, signalling the start or end of a string literal. Therefore, in order to give this character an alternative meaning of 'display a literal double-quote' when evaluated by the AutoLISP interpreter, it is prefixed with the backslash escape character.

For more information & resources on this point, see my post here.

Navigation

[0] Message Index

[#] Next page

Go to full version