本帖最后由 caddog 于 2012-7-27 14:06 编辑
因为经常会用到,所以我我写了一个函数.晒出来,见笑了.与君共勉.
- ;;---------------------------------------将字符串按分隔符解析为表-------------------------------
- (defun hj:Str2List (string symble / #REV $STR %ID LEN)
- (setq len (strlen string)
- %id 1
- #rev nil
- $str "" )
- (repeat len
- (if (and (vl-string-search (substr string %id 1) symble) (/= $str ""))
- (setq #rev (append #rev (list $str))
- $str "")
- (if (not (vl-string-search (substr string %id 1) symble) )
- (setq $str (strcat $str (substr string %id 1)))
- )
- )
- (setq %id (1+ %id))
- );_end repeat
- (if (/= $str "") (append #rev (list $str)) #rev)
- )
执行效果如下:
_$ (setq b (hj:Str2List "#1a@2ab#3abc@4abcd#5a@6a#" "#"))
("1a@2ab" "3abc@4abcd" "5a@6a")
|