求大神帮我改一下文本数字求和
这个文字前面或者中间有其他数字,就统计不出来,想要文字前面可以加数字,只统计文字后面的数字,多谢大神以下是复制的论坛帖子的源码:本工具用到的正则表达式的函数搬来此处。
;;--------------------------------------------正则表达式----------------------------------------------------;;
(defun xxexp (pat str key / end)
;(princ "\n ★"一刀屠文"(xxexp)(xxexpr) = 对字符串进行正则表达式测试及替换-by 梁雄啸.2007.7")
(vl-load-com)
(if (not *xxvbsexp)
(setq *xxvbsexp (vlax-get-or-create-object "VBScript.RegExp"))
)
(vlax-put *xxvbsexp 'Pattern pat)
(if (not key)(setq key ""))
(setq key (strcase key))
(setq keys '(("I""IgnoreCase")("G""Global")("M""Multiline")))
(mapcar '(lambda(x)
(if (wcmatch key (strcat "*" (car x) "*"))
(vlax-put *xxvbsexp (read(cadr x)) 0)
(vlax-put *xxvbsexp (read(cadr x)) -1)
))
keys)
(setq matches (vlax-invoke *xxvbsexp 'Execute str))
(vlax-for x matches (setq end (cons (vla-get-value x) end)))
(reverse end)
)
;;--------------------------------------------end----------------------------------------------------;;
本帖最后由 foolishzy 于 2023-5-26 11:46 编辑
(defun c:tttt()
(defun ZML-CLIP-SETSTRING (STR / HTML RESULT)
(and (= (type STR) 'STR)
(setq HTML (vlax-create-object "htmlfile"))
(setq RESULT (vlax-invoke
(vlax-get (vlax-get HTML 'PARENTWINDOW)
'CLIPBOARDDATA
)
'SETDATA
"Text"
STR
)
)
(vlax-release-object HTML)
)
)
(defun regexp(s p / r L )
(setq r (vlax-create-object "vbscript.regexp"))
(vlax-put-property r 'Global 1)
(vlax-put-property r 'Pattern p)
(vlax-for x (vlax-invoke r 'Execute s)(setq L (cons (vla-get-value x) L)))
(vlax-release-object r)
(reverse L)
)
(defun count-fruits (fruit-list)
(setq result (list))
(foreach item fruit-list
(setq fruit (car item))
(setq quantity (cadr item))
(if (assoc fruit result)
(setq quantity (+ quantity (cdr (assoc fruit result))))
)
(setq result (cons (cons fruit quantity) (vl-remove (assoc fruit result) result)))
)
result
)
(defun pickset_to_enamelist(pickset / ss sslst )
(setq ss pickset sslst '())
(while (setq n (ssname ss 0))
(progn
(setq sslst (append sslst (list n)))
(ssdel n ss)
)
)
sslst
)
(defun p1(str)
(vl-list->string (vl-remove 32 (vl-string->list str)))
(setq num (last (regexp str "\\d+")))
(setq head_str (vl-string-right-trim num str))
(list head_str (atoi num))
)
(setq ss(ssget '((0 . "*ext"))))
(setq lst (pickset_to_enamelist ss))
(setq name-lst (list))
(setq temp (list))
(foreach l lst
(setq temp (append temp(list (p1(Vlax-Get (Vlax-Ename->Vla-Object l) 'TextString )))))
)
(setq result (count-fruits temp))
(setq str "")
(mapcar (function (lambda (x)
(setq str(strcat str (car x) (itoa (cdr x)) "\n")
))
)
result
)
(ZML-CLIP-SETSTRING str)
(command "PASTECLIP" (getpoint "\n pick point : "))
)
不太会弄录屏 不太懂LISP,不过感觉问题和你这段代码无关,主要在正则pattern上,不知道原来是什么样的,可以改成^.+?\d+$试试。 兄弟你也用孤帆吗 谢谢分享,今天刚好没币了,此程序正是我需要的。 no function definition: XXEXP 显示出来这个
foolishzy 发表于 2023-5-26 11:33
大佬厉害,要是支持多行文本就好了
页:
[1]