Within quoted strings, the backslash (\) character allows control characters (or escape codes) to be included. The following table shows the currently recognized control characters:
AutoLISP control characters |
|
---|---|
Code |
Description |
\\ |
\ character |
\" |
" character |
\e |
Escape character |
\n |
Newline character |
\r |
Return character |
\t |
Tab character |
\nnn |
Character whose octal code is nnn |
The prompt and princ functions expand the control characters in a string and display the expanded string in the AutoCAD Command window.
If you need to use the backslash character (\) or quotation mark (") within a quoted string, it must be preceded by the backslash character (\). For example, if you enter
_$ (princ "The \"filename\" is: D:\\ACAD\\TEST.TXT. ")
the following text is displayed in the AutoCAD Command window:
The "filename" is: D:\ACAD\TEST.TXT
You will also see this output in the VLISP Console window, along with the return value from the princ function (which is your original input, with the unexpanded control characters).
To force a line break at a specific location in a string, use the newline character (\n).
_$ (prompt "An example of the \nnewline character. ")
An example of the
newline character.
You can also use the terpri function to cause a line break.
The return character (\r) returns to the beginning of the current line. This is useful for displaying incremental information (for example, a counter showing the number of objects processed during a loop).
The Tab character (\t) can be used in strings to indent or to provide alignment with other tabbed text strings. In this example, note the use of the princ function to suppress the ending nil.
_$ (prompt "\nName\tOffice\n- - - - -\t- - - - -
(_> \nSue\t101\nJoe\t102\nSam\t103\n") (princ)
Name |
Office |
---|---|
- - - - - |
- - - - - |
Sue |
101 |
Joe |
102 |
Sam |
103 |