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 |
prompt and princ functions expand the control characters in a string and display the expanded string in the AutoCAD Command window.
The\) or quotation mark (") within a quoted string, it must be preceded by the backslash character (\). For example, if you enter
If you need to use the backslash character (_$ (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
princ function (which is your original input, with the unexpanded control characters).
You will also see this output in the VLISP Console window, along with the return value from the\n).
To force a line break at a specific location in a string, use the newline character (_$ (prompt "An example of the \nnewline character. ")
An example of the
newline character.
terpri function to cause a line break.
You can also use the\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 return character (princ function to suppress the ending nil.
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_$ (prompt "\nName\tOffice\n- - - - -\t- - - - -
(_> \nSue\t101\nJoe\t102\nSam\t103\n") (princ)
Name |
Office |
---|---|
- - - - - |
- - - - - |
Sue |
101 |
Joe |
102 |
Sam |
103 |