如何将用逗号隔开的文字分开
文本中有好多行用逗号隔开的文字,比如"图元1,图元2,图元3",在用read-line函数读出该行后,怎么将图元1,图元2,图元3提取出来呢?请高手们指教! vl-string-left-trim或者vl-string-right-trim不知道对不对 (defun c:fd ()
(princ "打开文件所在文件夹\n选择文件:")
(setq name(getfiled "指定文件" (getvar "dwgprefix") "dwg" 0))
(setq position
(vl-string-search "\\" name 4))
(setq np position)
(while (numberp position )
(setq position
(vl-string-search "\\" name (1+ position)))
(if (/= position nil)(setq np position))
)
(setq tn(substr name 1 np))
(mapcar 'princ (list "\n文件路径=" tn))
(startapp "explorer" tn)
(prin1)
)
你根据这个改一改,就懒得给你具体弄了
(setq zfc (read-line wjm))
(while (vl-string-search "," zfc)
(setq zfc (vl-string-subst " " "," zfc))
)
(setq jgz (read (strcat "(" zfc ")")))
;jgz=(图元1图元2 ...) yshf 发表于 2014-3-11 22:07 static/image/common/back.gif
(setq zfc (read-line wjm))
(while (vl-string-search "," zfc)
(setq zfc (vl-string-subst " " " ...
这个不行,我用的就是这个方法,但是得出的结果是图元1,图元2,图元3……而不是"图元1","图元2","图元3"……,就是说结果不是字符串,然后呢就没法和字符串进行比较,比如说是否等于?你可以试验下。 本帖最后由 yshf 于 2014-3-14 20:00 编辑
要变字符串,再加一行不就了!
(setq jgz (mapcar '(lambda(x) (vl-princ-to-string x)) jgz))
或者
(setq jgz (mapcar 'vl-princ-to-string jgz)) ;; (Str2Lst "图元1,图元2,图元3" ",") → ("图元1" "图元2" "图元3")
(defun Str2Lst (str sprstr / lst m n a)
(setq lst '()
m (strlen sprstr)
)
(while (setq n (vl-string-search sprstr str))
(setq a (substr str 1 n)
str (substr str (+ n m 1))
lst (if (/= a "")
(cons a lst)
lst
)
)
)
(reverse (cons str lst))
) 本帖最后由 77077 于 2014-3-21 11:53 编辑
院长这次发的是真源码!赶紧收藏~~~
;;;
;;;读取文件并按行将文件转换为表 ;;;函数代码:
;;;(Txt2Lst "d:\\临时文件.txt")(defun Txt2Lst(files / tmplst x fn)
(setq files(findfile files))
(if files
(progn
(setq fn (openfiles "r"))
(while (setq x (read-line fn))
(setq txtlst(append txtlst (list x)))
)
(close fn)
txtlst
)
nil
)
)
页:
[1]