悬赏30币,如何删除括号后的字符
悬赏30币,如何删除括号后的字符,和括号前的字符,如123(2)455,删除括号后的字符为123(2),删除括号前的字符为455(defun c:tt ()
(setq ss(ssget '((0 . "*TEXT"))))
(setq en-list(try-ss2EnList ss))
(foreach n en-list (try-set-dxf n 1 (sut(try-get-dxf n 1))))
)
(defun sut (str)
(substr str 1 (1+ (vl-string-search ")" str)))
)
(defun try-ss2EnList(ss / a en lst)
(if ss(progn(setq a -1)
(while(setq en(ssname ss(setq a(1+ a))))
(setq lst(cons en lst)))))
lst)
(defun try-set-dxf (ename code val / ent x y i s1);注:原创为:xpy院长
(cond ((= (type ename) 'ENAME)
(setq ent (entget ename))
(if (and (= (type code) 'LIST) (= (type val) 'LIST))
(mapcar '(lambda (x y) (try-set-dxf ename x y)) code val)
(progn
(if (try-get-dxf ename code)
(entmod (subst (cons code val) (assoc code ent) ent))
(entmod (append ent (list (cons code val))))
)
(entupd ename)
)
)
)
((= (type ename) 'PICKSET)
(setq i -1)
(while (setq s1 (ssname ename (setq i (1+ i))))
(try-set-dxf s1 code val)
)
)
((= (type ename) 'LIST)
(foreach s1 ename (try-set-dxf s1 code val))
)
)
ename
)
(defun try-get-dxf (en code )
(cond ((= (type en) 'ENAME)
(cdr (assoc code (entget en))))
((= (type en) 'list)
(mapcar '(lambda(x)(try-get-dxf x code)) en))
((= (type en) 'PICKSET)
(try-get-dxf (try-ss2EnList en)code))
)
) 本帖最后由 aihuyujian 于 2016-1-13 14:41 编辑
(substr "123(2)455" 1 (+ (vl-string-search ")" "123(2)455") 2)) ;中文括号------------"123(2)"
(substr "123(2)455" 1 (+ (vl-string-search ")" "123(2)455") 1)) ;英文括号------------"123(2)"
(substr "123(2)455" (+ (vl-string-search ")" "123(2)455") 3)) ;中文括号------------"455"
(substr "123(2)455" (+ (vl-string-search ")" "123(2)455") 2)) ;英文括号------------"455" (defun LM:getfiles:str->lst ( str del / pos )
(if (setq pos (vl-string-search del str))
(cons (substr str 1 pos) (LM:getfiles:str->lst (substr str (+ pos 1 (strlen del))) del))
(list str)
)
)
(defun c:kk()
(car (LM:getfiles:str->lst"123(2)455" ")"))
) (vl-string-right-trim "1234567890" "123(2)455")
====>"123(2)" (defun c:tt (/ box data data2 en-list pt10 pt10-2 pt11 pt11-2 ss str txt1 txt2)
(setq ss(ssget '((0 . "*TEXT"))))
(setq en-list(try-ss2EnList ss))
;(setq n (entselx))
(foreach n en-list
(try-set-dxf n 1 (setq txt1(sut1(setq str(try-get-dxf n 1)))))
(setq
data(entget n)
pt10(try-get-dxf n 10)
pt11(try-get-dxf n 11)
box(textbox (subst (cons 1 (strcat "----" txt1))(cons 1 txt1)data))
txt2(sut2 str)
pt10-2 (mapcar '+ (list (car(cadr box))0)pt10)
pt11-2 (mapcar '+ (list (car(cadr box))0)pt11)
data2(cdr data)
data2(subst (cons 10 pt10-2)(cons 10 pt10)data2)
data2(subst (cons 11 pt11-2)(cons 11 pt11)data2)
data2(subst (cons 1 txt2)(cons 1 txt1)data2)
)
(entmakex data2)
)
)
(defun c:tt2 (/ en-list ss)
(setq ss(ssget '((0 . "*TEXT"))))
(setq en-list(try-ss2EnList ss))
(foreach n en-list (try-set-dxf n 1 (sut1(try-get-dxf n 1))))
)
(defun sut1(str / x)
(setq x(car(try-StrRegExp str "[^\\))]+[\\))]")))
(if x x str)
)
(defun sut2(str / x)
(setq x(last(try-StrRegExp str "[^\\))]+")))
(if x x str)
)
(defun try-ss2EnList(ss / a en lst)
(if ss(progn(setq a -1)
(while(setq en(ssname ss(setq a(1+ a))))
(setq lst(cons en lst)))))
lst)
(defun try-set-dxf (ename code val / ent x y i s1);注:原创为:xpy院长
(cond ((= (type ename) 'ENAME)
(setq ent (entget ename))
(if (and (= (type code) 'LIST) (= (type val) 'LIST))
(mapcar '(lambda (x y) (try-set-dxf ename x y)) code val)
(progn
(if (try-get-dxf ename code)
(entmod (subst (cons code val) (assoc code ent) ent))
(entmod (append ent (list (cons code val))))
)
(entupd ename)
)
)
)
((= (type ename) 'PICKSET)
(setq i -1)
(while (setq s1 (ssname ename (setq i (1+ i))))
(try-set-dxf s1 code val)
)
)
((= (type ename) 'LIST)
(foreach s1 ename (try-set-dxf s1 code val))
)
)
ename
)
(defun try-get-dxf (en code )
(cond ((= (type en) 'ENAME)
(cdr (assoc code (entget en))))
((= (type en) 'list)
(mapcar '(lambda(x)(try-get-dxf x code)) en))
((= (type en) 'PICKSET)
(try-get-dxf (try-ss2EnList en)code))
)
)
(defun try-StrRegExp(str1 expr)
(_Replace str1 expr nil "")
)
(defun _Replace(str1 str2 bull str3 / lst matchcollect reg)
(setq lst '())
(setq reg (vlax-create-object "vbscript.regexp")) ;创建正则表达式
(if (null reg)(progn(alert "发现系统vbscript没有注册,现尝试对其注册")(command"shell" "regsvr32 vbscript.dll")(setq reg (vlax-create-object "vbscript.regexp"))))
(vlax-put-property reg 'global -1) ;是否匹配全部 (-1是 ,0 不是)
(vlax-put-property reg 'Multiline -1);是否多行匹配 (-1是 ,0 不是)
(vlax-put-property reg 'IgnoreCase -1);是否忽略大小写 (-1是 ,0 不是)
(vlax-put-property reg 'pattern str2);lisp \\
;;; 1.(vlax-invoke-method reg 'test str)判断字符串是否与正则表达式匹配
(if (vlax-invoke-method reg 'test str1)
;;; 2.(vlax-invoke-method reg 'Execute str)生成匹配集合
(progn (setq matchcollect (vlax-invoke-method reg 'Execute str1))
;;; 3.打印匹配的每个集合元素的value
(vlax-for match_item matchcollect (setq lst(cons(eval (vlax-get-property match_item 'value))lst)))
)
)
;;; 4.替换匹配的值(vlax-invoke-method reg 'Replace str "replace")生成str副本
(setq lst(reverse lst))
(if bull
(setq lst(vlax-invoke-method reg 'Replace str1 str3)))
;;;----------------- end 正则表达式方法
(vlax-release-object reg);释放内存
lst
)
原创为:xpy院长
院长看到这个该生气了。 删除括号,和括号内的文字。怎么改?
页:
[1]