| ASCII 代码是表示字母数字字符的整数值。 数值 0 到 127 表示数字 0 到 9、字母表、标点符号和其他特殊字符。某些 AutoLISP 函数返回或期望单个字符的 ASCII 代码,而不是等效的字符串。 例如,该函数返回用户提供键盘输入时按下的键的 ASCII 代码。然后,可以根据程序如何使用返回的列表中的 ASCII 代码进行评估或转换以显示。grread 以下是使用 ASCII 代码时使用的一些 AutoLISP 函数: 
 将 ASCII 代码和字符转换为 ASCII 代码and 函数可用于处理 ASCII 代码的转换。该函数返回与字符串关联的 ASCII 代码,并返回与 ASCII 代码关联的字符串。asciichrasciichr 以下代码将大写字母 A 转换为其 ASCII 代码值: (ascii "A") 65 以下代码将 ASCII 代码值转换为它所表示的字符串: (chr 65) "A" 下面的示例代码定义了该命令使用的名为的命令和名为的函数。该命令将字符及其代码以十进制、八进制和十六进制形式写入屏幕和名为 ASCII.txt 的文件。ASCIIBASEASCIIASCII ; BASE converts from a decimal integer to a string in another base.
(defun BASE (bas int / ret yyy zot)
  (defun zot (i1 i2 / xxx)
    (if (> (setq xxx (rem i2 i1)) 9)
      (chr (+ 55 xxx))
      (itoa xxx)
    )
  )
  (setq ret (zot bas int)
        yyy (/ int bas)
  )
  (setq ret (strcat (zot bas yyy) ret))
  (setq yyy (/ yyy bas))
  (strcat (zot bas yyy) ret)
)
(defun C:ASCII (/)                      ;chk out ct code dec oct hex )
  (initget "Yes")
  (setq chk (getkword "\nWriting to ASCII.TXT, continue? <Y>: "))
  (if (or (= chk "Yes") (= chk nil))
    (progn
      (setq out  (open "ascii.txt" "w")
            chk  1
            code 0
            ct   0
      )
      (princ "\n \n CHAR DEC OCT HEX \n")
      (princ "\n \n CHAR DEC OCT HEX \n" out)
      (while chk
        (setq dec (strcat "  " (itoa code))
              oct (base 8 code)
              hex (base 16 code)
        )
        (setq dec (substr dec (- (strlen dec) 2) 3))
        (if (< (strlen oct) 3)
          (setq oct (strcat "0" oct))
        )
        (princ (strcat "\n " (chr code) " " dec " " oct " " hex))
        (princ (strcat "\n " (chr code) " " dec " " oct " " hex)
               out
        )
        (cond
          ((= code 255) (setq chk nil))
          ((= ct 20)
           (setq
             xxx (getstring
                   "\n \nPress 'X' to eXit or any key to continue: "
                 )
           )
           (if (= (strcase xxx) "X")
             (setq chk nil)
             (progn
               (setq ct 0)
               (princ "\n \n CHAR DEC OCT HEX \n")
             )
           )
          )
        )
        (setq ct   (1+ ct)
              code (1+ code)
        )
      )
      (close out)
      (setq out nil)
    )
  )
 (princ)
)父主题: | 
 |Archiver|CAD开发者社区
( 苏ICP备2022047690号-1   苏公网安备32011402011833)
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1   苏公网安备32011402011833)
GMT+8, 2025-11-1 01:14
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.