明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3002|回复: 5

[函数] 特殊字符处理(用于文字替换等)

  [复制链接]
发表于 2013-10-9 14:40 | 显示全部楼层 |阅读模式
;;[功能] 特殊字符处理(用于文字替换等)
;;示例(ACET-STR-ESC-WILDCARDS1 "#a@b");"`#a`@b"
;;注:没有安装ET时用,安装ET后用(ACET-STR-ESC-WILDCARDS "#a@b")
;;http://bbs.mjtd.com/forum.php?mo ... d=608841&page=2中定义XD::String:Replace
(defun ACET-STR-ESC-WILDCARDS1 (A / X LST)
  ;;(ACET-STR-REPLACE "B" "2" "ssABCsBs");"ssA2Cs2s"
  (defun ACET-STR-REPLACE1 (o n s)
    (XD::String:Replace (strcat "[" o "]") s n "I")
  )
  (SETQ LST '("#" "@" "." "*" "?" "~" "[" "]" ","))
  (foreach X LST
    (SETQ A (ACET-STR-REPLACE1 X (STRCAT "`" X) A))
  )
  A
)
"觉得好,就打赏"
还没有人打赏,支持一下

本帖被以下淘专辑推荐:

发表于 2013-11-26 22:09 | 显示全部楼层
http://bbs.mjtd.com/forum.php?mo ... d=608841&page=2
打不开
能否直接贴出XD::String:Replace?
谢谢黄兄
发表于 2013-11-26 22:22 | 显示全部楼层
找到了
;; 用正则表达式替换字符 by 梁雄啸.2007.7
(defun XD::String:Replace (pat str nstr key / end)  
  (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)
  (vlax-invoke *xxvbsexp 'replace str nstr)
)
发表于 2018-8-2 13:27 | 显示全部楼层
print1985 发表于 2013-11-26 22:22
找到了
;; 用正则表达式替换字符 by 梁雄啸.2007.7
(defun XD::String:Replace (pat str nstr key / end) ...

怎么用啊??????
发表于 2018-8-26 03:21 | 显示全部楼层
大神牛牛牛牛!
发表于 2019-4-5 21:33 | 显示全部楼层
;函数名称:        XD::String:Replace
;调用格式:        (XD::String:Replace old new str)
;参数说明:        old ---- 旧字符串
;new ---- 新字符串
;str --- 字符串
;返回值:        字符串
;函数简介:        字符串替换
;函数来源:        原创
;函数作者:        marting
(defun XD::String:Replace (oldtext newtext textstring / i n)
  (setq n (strlen newtext))
  (while (setq i (vl-string-search oldtext textstring i))
    (setq textstring
                        (vl-string-subst newtext oldtext textstring i)
                        i (+ i n)
    )
  )
  textstring
)

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-25 17:08 , Processed in 0.336135 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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