看到坛友在讨论拆分字符串,提供一个另类的拆分函数。
主要用在我另外两个帖子中的程序:DZ和FA
- ;将字符串拆分成单字符列表
- (defun K:ExplodeSTR (STR / Defined STRDefined RtnSTR Pos)
- (setq Defined
- (List
- "%%130" "%%131" "%%132" "%%133" "%%134" ;1~4级钢筋符号+特殊钢筋
- "%%135" "%%136" "%%137" "%%138" ;L型钢+H型钢+槽型钢+工字钢
- "%%150" "%%151" "%%152" "%%153" "%%154" "%%155" "%%156" "%%157" "%%158" "%%159" ;罗马数字
- "%%177" "%%p" "%%P" ;正负号
- "%%c" "%%C" "%%D" "%%d" "%%%";直径符号+度数符号+%
- '("%%140" "%%141") '("%%142" "%%143") ;上下标开关
- '("%%200" "%%201") '("%%202" "%%203") '("%%204" "%%205") ;圆圈数字
- )
- )
- (while (> (strlen STR) 0)
- (cond
- ((setq STRDefined
- (vl-some
- '(lambda (Sub / STRDefined)
- (setq STRDefined (if (listp Sub) (car Sub) Sub))
- (if (eq (substr STR 1 (strlen STRDefined)) STRDefined) Sub)
- )
- Defined
- )
- )
- (if (listp STRDefined)
- (if (setq Pos (vl-string-search (cadr STRDefined) STR))
- (progn
- (setq RtnSTR (cons (substr STR 1 (+ Pos (strlen (cadr STRDefined)))) RtnSTR))
- (setq STR (substr STR (+ 1 Pos (strlen (cadr STRDefined)))))
- )
- (progn
- (setq RtnSTR (cons STR RtnSTR))
- (setq STR "");清空
- )
- )
- (progn
- (setq RtnSTR (cons STRDefined RtnSTR))
- (setq STR (substr STR (1+ (strlen STRDefined))))
- )
- )
- )
- ((> (ascii (substr STR 1 1)) 128) ;大于128为汉字
- (if
- (and
- (>= (atoi (substr (ver) 13)) 2021)
- (/= (getvar "lispsys") 0)
- )
- (progn
- (setq RtnSTR (cons (substr STR 1 1) RtnSTR))
- (setq STR (substr STR 2))
- )
- (progn
- (setq RtnSTR (cons (substr STR 1 2) RtnSTR))
- (setq STR (substr STR 3))
- )
- )
- )
- (T
- (setq RtnSTR (cons (substr STR 1 1) RtnSTR))
- (setq STR (substr STR 2))
- )
- )
- )
- (reverse RtnSTR)
- )
|