雪山飞狐_lzh 发表于 2004-7-9 23:18:00

[原创]通配符替换程序

Public Sub SuperReplace()<BR>'支持通配符*格式的替换<BR>'例:*(*)-&gt;*[*]或A*B*-&gt;B*C*<BR>'支持替换前后*的数量不等<BR>On Error Resume Next<BR>Dim ss As AcadSelectionSet<BR>Dim str As String<BR>Dim pStart As String, pEnd As String<BR>Dim i As AcadEntity, j<BR>Dim ft(1) As Integer, fd(1)<BR>Dim pSS, pES<BR>Dim pStrs() As String<BR>Dim pSpec As String


ThisDrawing.SelectionSets("*TlsText*").Delete<BR>Set ss = ThisDrawing.SelectionSets.Add("*TlsText*")


pStart = Trim(ThisDrawing.Utility.GetString(True, "替换前:"))<BR>pEnd = Trim(ThisDrawing.Utility.GetString(True, "替换后:"))<BR>pSS = Split(pStart, "*")<BR>pES = Split(pEnd, "*")<BR>pSpec = Replace(pStart, "`", "``")<BR>pSpec = Replace(pSpec, "[", "`[")<BR>pSpec = Replace(pSpec, "]", "`]")<BR>pSpec = Replace(pSpec, ",", "`,")<BR>pSpec = Replace(pSpec, "@", "`@")<BR>pSpec = Replace(pSpec, "~", "`~")<BR>pSpec = Replace(pSpec, ".", "`.")<BR>pSpec = Replace(pSpec, "?", "`?")<BR>ft(0) = 0: fd(0) = "*Text"<BR>ft(1) = 1: fd(1) = pSpec<BR>ss.SelectOnScreen ft, fd


For Each i In ss<BR>If UBound(pES) = 0 Then<BR>i.TextString = pEnd<BR>Else<BR>str = i.TextString<BR>ReDim pStrs(UBound(pSS) + 1) As String<BR>For j = 0 To UBound(pSS)<BR>pStrs(j) = LeftStr(str, pSS(j)) &amp; pES(j)<BR>str = RightStr(str, pSS(j))<BR>Next j


pStrs(UBound(pSS) + 1) = str<BR>i.TextString = Join(pStrs, "")<BR>End If<BR>Next i


ThisDrawing.SelectionSets("*TlsText*").Delete


End Sub

zazhz123 发表于 2011-9-21 21:18:48

怎么用法、?

zazhz123 发表于 2011-9-21 21:20:38

老大能否讲讲,我正在找能替换例如"!#-LM@2“为"!#KK@2“,谢谢

zyhandw 发表于 2011-10-20 11:00:15

看不太懂vba的,想看是lsp的!

清风明月名字 发表于 2013-6-28 20:19:17

谢谢分享,学习一下

eii 发表于 2016-2-17 23:59:51

顶顶顶,备用。。。

满山松叶 发表于 2016-3-14 09:33:26

Vba不懂,学习一下

LIULISHENG 发表于 2017-9-25 16:10:08


pengfei2010 发表于 2017-10-9 14:42:49

回帖是一种美德!感谢楼主的无私分享 谢谢

逍遥天下 发表于 2017-10-14 13:27:09

有演示吗,感谢分享源码
页: [1] 2
查看完整版本: [原创]通配符替换程序