本帖最后由 dcl1214 于 2024-9-11 08:27 编辑
最近遇到多人画图的时候,每个人自己有一个代号,用来标注物料球,或者是图纸中某一些图形用特殊前缀加数字尾缀来做区分的情况,我在提取数据的时候,经常需要做分类,而且还要查漏补缺,所以,我写了一个遇到数字断开的函数
- (defun $yu-dao-shu-zi-duan-kai$
- (str pos pos-fh / a go n-i s1 ss str-n str-num str->chrlist )
- ;遇到数字断开
- ;pos 正向还是反向,传入数字0代表从第一位开始,传入数字1代表从最后一位开始分析
- ;pos-fh 0代表从断开点往左的返回,1代表是从断开点往右的返回
- ;($yu-dao-shu-zi-duan-kai$ "BD15A" 0 0)
- (defun str->chrlist (str / lst carlst cadrlst relst)
- ;字符串转表,不是分割成表
- (AND str (setq lst (vl-string->list str)))
- (while lst
- (setq carlst (car lst))
- (setq cadrlst (cadr lst))
- (if (< carlst 129)
- (progn (setq relst (cons (list carlst) relst))
- (setq lst (cdr lst))
- )
- (progn (setq relst (cons (list carlst cadrlst) relst))
- (setq lst (cddr lst))
- )
- )
- )
- (IF relst
- (mapcar 'vl-list->string (reverse relst))
- )
- )
- (or pos (setq pos 0))
- (and str (setq ss (str->chrlist str)))
- (and (= pos 1) (setq ss (reverse ss)))
- (SETQ s1 NIL)
- (setq go t)
- (while (and go (setq a (car ss)))
- (if (AND A
- (member a (list "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"))
- )
- (progn
- (setq go nil)
- )
- (setq s1 (cons a s1))
- )
- (if go
- (setq ss (cdr ss))
- )
- )
- (setq s1 (reverse s1))
- (IF (= pos 1)
- (PROGN
- (setq ss (reverse ss))
- (AND S1 (setq s1 (reverse s1)))
- )
- )
- (OR
- (and ss (= pos-fh 1) (setq str-n (apply 'strcat ss)))
- (and ss (= pos-fh 0) (setq str-n (apply 'strcat s1)))
- (setq str-n (apply 'strcat s1))
- )
- str-n
- )
|