TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MeasureUp on June 11, 2019, 03:25:03 AM
-
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:
(setq UserInput (getstring "Enter Letters: "))
(strcat "Your Input is " ... UserInput ... ".")
The message should be shown as below if the input was ABC.
Your Input is "ABC".
Your helps are much appreciated.
-
(strcat "Your Inout is \"" UserInput
"\".")
-
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.:
Command: (getstring t "\nEnter string: ")
Enter string: Your input is "ABC"
"Your input is \"ABC\""
-
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.
"Your input is \"ABC\"."
But when "princ" is added it shows correctly at command line.
(princ (strcat "Your Input is \"" UserInput "\"."))
Your input is "ABC".
-
My confusion is the resault I got.
"Your input is \"ABC\"."
But when "princ" is added it shows correctly at command line.
(princ (strcat "Your Input is \"" UserInput "\"."))
Your input is "ABC".
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 (https://www.cadtutor.net/forum/topic/49426-insert-quot-symbol-in-a-string/?tab=comments#comment-409254).
-
Alternative:
-
Thanks Lee.
And to frostmourn, agreed with the term of "alternative".