寻找一个含前后缀的数字文本加减替换的lsp程序
我想把“33”、“34a”、“a35”……这些单行文字加(或减)一个常数比如10,替换为“43”、“44a”、“a45”……恳请高手出手相助! 本帖最后由 自贡黄明儒 于 2013-10-28 16:49 编辑
;;如是前后有整数,那就好办了
(defun NumberChange (str num / STR1 STR2)
(cond ((setq str1 (car (xd::string:regexps "\\d+$$" str "")))
(setq str2 (itoa (+ (atoi str1) num)))
(XD::String:Replace "\\d+$$" str str2 "")
)
((setq str1 (car (xd::string:regexps "^\\d+" str "")))
(setq str2 (itoa (+ (atoi str1) num)))
(XD::String:Replace "^\\d+" str str2 "")
)
)
)
(defun C:w1 (/ EN ENTLIS N SS STR)
(if (setq ss (ssget '((1 . "*#*"))))
(repeat (setq n (sslength ss))
(setq en (ssname ss (setq n (1- n))))
(setq entlis (entget en))
(setq str (cdr (assoc 1 entlis)))
(if (setq str (NumberChange str 10))
(entmod (subst (cons 1 str) (assoc 1 entlis) entlis))
)
)
)
)
自贡黄明儒 发表于 2013-10-28 13:38 static/image/common/back.gif
;;如是前后有整数,那就好办了
谢谢黄明儒的提供的源码,但是选择要替换的文本确认时出现如下错误:
; 错误: no function definition: XD::STRING:REGEXPS 同样选择要替换的文本确认时出现如下错误:
; 错误: no function definition: XD::STRING:REGEXPS
页:
[1]