明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1005|回复: 1

[提问] 为什么一次只能替换一个

[复制链接]
发表于 2014-2-26 11:39:32 | 显示全部楼层 |阅读模式
这是一个字符替换的程序,请问当文字里同时有多个要替换的字符时,为什么一次只能替换一个?
(vl-load-com)
(defun c:tt (/ ss n ent obj txt i)
  (if (setq ss (ssget '((0 . "*TEXT") )))
    (repeat (setq n (sslength ss))
      (setq ent (ssname ss (setq n (1- n))))
      (setq obj (vlax-ename->vla-object ent))
      (setq txt (vla-get-textstring obj))
      (cond
((wcmatch txt "*a*")
  (setq txt (ReplaceText "%%130" "a" txt))
)
((wcmatch txt "*d*")
  (setq txt (ReplaceText "%%131" "d" txt))
)
((wcmatch txt "*f*")
  (setq txt (ReplaceText "%%132" "f" txt))
)
((wcmatch txt "*A*")
  (setq txt (ReplaceText "%%130" "A" txt))
)
((wcmatch txt "*D*")
  (setq txt (ReplaceText "%%131" "D" txt))
)
((wcmatch txt "*F*")
  (setq txt (ReplaceText "%%132" "F" txt))
)
      )
      (vla-put-textstring obj txt)
    )
  )
  (princ)
)
(defun ReplaceText (NewStr oldstr string / txt)
  (setq txt string)
  (while (vl-string-search oldstr txt)
    (setq txt (VL-STRING-SUBST NewStr oldstr txt))
  )
  txt
)


"觉得好,就打赏"
还没有人打赏,支持一下
 楼主| 发表于 2014-2-26 17:07:49 | 显示全部楼层
自己顶一个
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-25 09:34 , Processed in 0.334621 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表