Lesson39 – Formatting Strings with Control Codes



Some simple formatting of text can be handled through the use of expanded ASCII codes or control codes. We have already seen one of these, “\n”, which generates a new line. Here are some others that may be useful.

Note that multiple control codes can be used within the same string.

  • The control codes must be within the double quotes.
  • The control codes must be lowercase.

Example

Command: (prompt “This text \nis on \nthree lines with a \ttab.”)
This text

is on
three lines with a                     tab.nil

Translating ASCII Codes

Two other functions will help you work with specialty ASCII characters.

(ascii string)

Changes the string to the appropriate ASCII character as an integer.

(chr integer)

Changes the integer to the appropriate ASCII string.
Command: (ascii “N”)
78
Command: (chr 78)
“N”

PRACTICE

Open the drawing file BLOX.DWG and then edit the LISP file BOM.LSP so that there is a title showing “Number” and “Name”, the prompts are joined together with (strcat), and there are tabs between the information so that the returned information is easier to read.

(defun c:BOM ()
(setq BLK-INFO (tblnext “BLOCK” T))
(prompt “\n NUMBER \t\tNAME”)
(prompt “\n——————–“)
(while BLK-INFO
(setq BLK-NM (cdr (assoc 2 BLK-INFO)))
(setq SS1 (ssget “X”
(list (cons 0 “INSERT”)
(cons 2 BLK-NM)
) ;_ end of list
) ;_ end of ssget
) ;_ end of setq
(if SS1
(setq COUNT (sslength SS1))
(setq COUNT 0) ) ;_ end of if

(prompt (strcat “\n \t” (itoa COUNT) “\t \t” BLK- NM))
(setq BLK-INFO (tblnext “BLOCK”))
) ;_ end of while
(princ)
) ;_ end of defun

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

Show Buttons
Hide Buttons
SUBSCRIBE TO OUR NEWSLETTER

It's FREE!

Sign up and receive an email every time a new tutorial is published