- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
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 |
|