- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2004-6-25 23:32:00
|
显示全部楼层
本帖最后由 作者 于 2004-6-27 13:00:15 编辑
我又改进了一下,下面的程序基本可用。3楼的代码又重写了一遍- Public Function GetMTextUnformatString(ByVal str As String) As String
- '程序功能:按给定的MText字符串返回可用的字符串
- On Error Resume Next Dim pStrs As New Collection
- Dim pStack As Collection
- Dim n As Integer
- Dim pStr As String
- Dim pEnd As String
-
- str = "{" & str & "}"
- Do While Len(str) > 0
-
- n = IIf(Left(str, 1) = "", 2, 1)
- pStr = Left(str, n)
- '分割MText字符串为控制字符或单个字符
-
- If pStr = "}" Then
- '遇"}"时出栈,直到"{"
-
- pEnd = pStrs(pStrs.Count)
- Set pStack = New Collection
- pStack.Add "*TlsCad*"
-
- Do While pEnd <> "{"
-
- pStack.Add pEnd, , 1
- pStrs.Remove pStrs.Count
- pEnd = pStrs(pStrs.Count)
-
- Loop
-
- pStrs.Remove pStrs.Count
- pStack.Remove pStack.Count
-
- For Each i In GetRtfString(pStack)
- '调用GetRtfString函数返回可用的字符集合
-
- pStrs.Add i
-
- Next i
-
- Else
- '当前字符入栈
- pStrs.Add Left(str, n)
-
- End If
-
- str = Right(str, Len(str) - n)
-
- Loop
-
- For Each i In pStrs
- '合并字符集合为字符串
- If Len(i) = 2 Then
- '处理\、{、}
- GetMTextUnformatString = GetMTextUnformatString & Right(i, 1)
-
- Else
-
- GetMTextUnformatString = GetMTextUnformatString & i
-
- End If
-
- Next i
-
- End FunctionPrivate Function GetRtfString(ByVal stack As Collection) As Collection
- '程序功能:按给定的Rtf字符集合返回可用的字符集合 Dim pStrs As New Collection
- Dim pStr As String, pType As Long
- Dim i, j
-
- For Each i In stack
-
- If Len(i) = 1 Then
-
- pStrs.Add i
-
- ElseIf Len(i) = 2 Then
-
- pType = Asc(UCase(Right(i, 1)))
-
- Select Case pType
-
- Case 85, 92, 123, 125
- '\ or { or } or U
-
- pStrs.Add i
-
- Case 65, 67, 70, 72, 81, 84, 87
- 'A or C or F or H or Q or T or W
-
- Do While stack(1) <> ";"
- stack.Remove 1
- Loop
- stack.Remove 1
-
- Case 76, 79, 80
- 'L or O or P
-
- Case 83
- 'S
-
- stack.Remove 1
- Do While stack(1) <> ";"
- If stack(1) <> "^" Then
- pStrs.Add stack(1)
- End If
- stack.Remove 1
- Loop
- stack.Remove 1
-
- Case 126
- '~
-
- pStrs.Add " "
-
- End Select
-
- End If
-
- Next i Set GetRtfString = pStrs
-
- End Function
|
|