Author Topic: How to Add Double Quotes in A Message  (Read 2588 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 461
How to Add Double Quotes in A Message
« 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:
Code: [Select]
(setq UserInput (getstring "Enter Letters: "))
(strcat "Your Input is " ... UserInput ... ".")

The message should be shown as below if the input was ABC.
Quote
Your Input is "ABC".

Your helps are much appreciated.

kpblc

  • Bull Frog
  • Posts: 396
Re: How to Add Double Quotes in A Message
« Reply #1 on: June 11, 2019, 03:40:36 AM »
Code - Auto/Visual Lisp: [Select]
  1. (strcat "Your Inout is \"" UserInput "\".")
Sorry for my English.

Lee Mac

  • Seagull
  • Posts: 12904
  • London, England
Re: How to Add Double Quotes in A Message
« Reply #2 on: June 11, 2019, 08:31:01 AM »
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: [Select]
Command: (getstring t "\nEnter string: ")
Enter string: Your input is "ABC"
"Your input is \"ABC\""

MeasureUp

  • Bull Frog
  • Posts: 461
Re: How to Add Double Quotes in A Message
« Reply #3 on: June 11, 2019, 07:18:23 PM »
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\"."
But when "princ" is added it shows correctly at command line.
Code: [Select]
(princ (strcat "Your Input is \"" UserInput "\"."))
Quote
Your input is "ABC".

Lee Mac

  • Seagull
  • Posts: 12904
  • London, England
Re: How to Add Double Quotes in A Message
« Reply #4 on: June 12, 2019, 08:14:13 AM »
My confusion is the resault I got.
Quote
"Your input is \"ABC\"."
But when "princ" is added it shows correctly at command line.
Code: [Select]
(princ (strcat "Your Input is \"" UserInput "\"."))
Quote
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.

frostmourn

  • Mosquito
  • Posts: 4
Re: How to Add Double Quotes in A Message
« Reply #5 on: June 13, 2019, 04:37:41 AM »
Alternative:
Code - Auto/Visual Lisp: [Select]
  1. (princ "Your Input is ")
  2. (prin1 "ABC")
  3. (princ ".")

MeasureUp

  • Bull Frog
  • Posts: 461
Re: How to Add Double Quotes in A Message
« Reply #6 on: June 14, 2019, 02:15:51 AM »
Thanks Lee.
And to frostmourn, agreed with the term of "alternative".