[原创]通配符替换程序
Public Sub SuperReplace()<BR>'支持通配符*格式的替换<BR>'例:*(*)->*[*]或A*B*->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 StringThisDrawing.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)) & 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 怎么用法、? 老大能否讲讲,我正在找能替换例如"!#-LM@2“为"!#KK@2“,谢谢 看不太懂vba的,想看是lsp的! 谢谢分享,学习一下 顶顶顶,备用。。。 Vba不懂,学习一下
回帖是一种美德!感谢楼主的无私分享 谢谢 有演示吗,感谢分享源码
页:
[1]
2