明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4725|回复: 10

[原创]通配符替换程序

[复制链接]
发表于 2004-7-9 23:18:00 | 显示全部楼层 |阅读模式
Public Sub SuperReplace()
'支持通配符*格式的替换
'例:*(*)->*
  • 或A*B*->B*C*
    '支持替换前后*的数量不等
    On Error Resume Next
    Dim ss As AcadSelectionSet
    Dim str As String
    Dim pStart As String, pEnd As String
    Dim i As AcadEntity, j
    Dim ft(1) As Integer, fd(1)
    Dim pSS, pES
    Dim pStrs() As String
    Dim pSpec As String ThisDrawing.SelectionSets("*TlsText*").Delete
    Set ss = ThisDrawing.SelectionSets.Add("*TlsText*") pStart = Trim(ThisDrawing.Utility.GetString(True, "替换前:"))
    pEnd = Trim(ThisDrawing.Utility.GetString(True, "替换后:"))
    pSS = Split(pStart, "*")
    pES = Split(pEnd, "*")
    pSpec = Replace(pStart, "`", "``")
    pSpec = Replace(pSpec, "[", "`[")
    pSpec = Replace(pSpec, "]", "`]")
    pSpec = Replace(pSpec, ",", "`,")
    pSpec = Replace(pSpec, "@", "`@")
    pSpec = Replace(pSpec, "~", "`~")
    pSpec = Replace(pSpec, ".", "`.")
    pSpec = Replace(pSpec, "?", "`?")
    ft(0) = 0: fd(0) = "*Text"
    ft(1) = 1: fd(1) = pSpec
    ss.SelectOnScreen ft, fd For Each i In ss
    If UBound(pES) = 0 Then
    i.TextString = pEnd
    Else
    str = i.TextString
    ReDim pStrs(UBound(pSS) + 1) As String
    For j = 0 To UBound(pSS)
    pStrs(j) = LeftStr(str, pSS(j)) & pES(j)
    str = RightStr(str, pSS(j))
    Next j pStrs(UBound(pSS) + 1) = str
    i.TextString = Join(pStrs, "")
    End If
    Next i ThisDrawing.SelectionSets("*TlsText*").Delete End Sub
  • 点评

    谢谢分享  发表于 2012-3-15 19:27
    发表于 2011-9-21 21:18:48 | 显示全部楼层
    怎么用法、?
    发表于 2011-9-21 21:20:38 | 显示全部楼层
    老大能否讲讲,我正在找能替换例如"!#-LM@2“为"!#KK@2“,谢谢
    发表于 2011-10-20 11:00:15 | 显示全部楼层
    看不太懂vba的,想看是lsp的!
    发表于 2013-6-28 20:19:17 | 显示全部楼层
    谢谢分享,学习一下
    发表于 2016-2-17 23:59:51 | 显示全部楼层
    顶顶顶,备用。。。
    发表于 2016-3-14 09:33:26 | 显示全部楼层
    Vba不懂,学习一下
    发表于 2017-10-9 14:42:49 | 显示全部楼层
    回帖是一种美德!感谢楼主的无私分享 谢谢
    发表于 2017-10-14 13:27:09 | 显示全部楼层
    有演示吗,感谢分享源码
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

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

    GMT+8, 2024-11-25 10:55 , Processed in 0.173400 second(s), 24 queries , Gzip On.

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

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