使用DOSLIB函式库之DOS_STRTOKENS函数将字串转成串列较为简捷,但须依CAD版别载入DOSLIB函式库
假设有一个文本档案为aaa.txt,文件内容如下: 1,2133,4645 2,123123,4564
读取后串列资料为 ALAN_S=' ("1,2133,4645" "2,123123,4564")
(DEFUN C:ALAN (/ ALAN_S ITEMLIST NUM A B)
(LOAD_DOSLIB)
(SETQ ALAN_S '("1,2133,4645" "2,123123,4564") ITEMLIST '() NUM 0)
(REPEAT (LENGTH ALAN_S)
(SETQ ITEMLIST (APPEND ITEMLIST (LIST (DOS_STRTOKENS (NTH NUM ALAN_S) ","))))
(SETQ NUM (+ NUM 1))
)
(SETQ A (NTH 0 (NTH 1 ITEMLIST)) B (NTH 2 (NTH 1 ITEMLIST)))
)
(DEFUN LOAD_DOSLIB (/ AC_VER);←依CAD版别载入DOSLIB函式库
(SETQ AC_VER (SUBSTR (GETVAR "ACADVER") 1 2))
(IF (NOT DOS_DRIVE)
(PROGN
(COND ((AND (= AC_VER "13")(WCMATCH (STRCASE (GETVAR "PLATFORM")) "*DOS*"))
(XLOAD "DOSLIB13")
)
((= AC_VER "12")(XLOAD "DOSLIB12"))
(T (ARXLOAD (STRCAT "DOSLIB" AC_VER)))
)
)
)
)
(PRINC "\nALAN 程式已载入 !")(PRINC "\n")
(PROMPT "----------------------------<< C:ALAN >>------------------------------\n") (PRINC)
上网搜寻DOSLIB就可下载 |