- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2004-5-20 20:55:00
|
显示全部楼层
本帖最后由 作者 于 2004-6-25 23:29:37 编辑
这是改进版,已基本解决问题,欢迎测试- Public Function FindStr(ByVal str As Variant, ByVal Target As Variant)
- str = Replace(str, "\", "**")
- str = Replace(str, "" & Target, "**")
- FindStr = InStr(str, Target)
- End FunctionPublic Function LeftStr(ByVal String1 As Variant, ByVal String2 As Variant)
- On Error Resume Next
- LeftStr = Left(String1, FindStr(String1, String2) - 1)
- If Err Then LeftStr = ""
- End FunctionPublic Function RightStr(ByVal String1 As Variant, ByVal String2 As Variant)
- On Error Resume Next
- RightStr = Right(String1, Len(String1) - Len(String2) - FindStr(String1, String2) + 1)
- If Err Then RightStr = ""
- End FunctionPublic Function FindMirrorString(ByVal str As String, ByVal StartStr As String, ByVal EndStr As String) As Integer
- Dim pStart As Integer, pEnd As Integer
- Dim pSNum As Integer, pENum As Integer
- FindMirrorString = FindStr(str, StartStr)
- If FindMirrorString = 0 Then Exit Function
- FindMirrorString = 0
- Do While pStart = 0 Or pEnd = 0 Or pStart <> pEnd
- pSNum = FindStr(str, StartStr): pENum = FindStr(str, EndStr)
- If pENum = 0 Then
- FindMirrorString = 0: Exit Function
- ElseIf pSNum < pENum And pSNum <> 0 Then
- pStart = pStart + 1
- FindMirrorString = FindMirrorString + pSNum
- str = RightStr(str, StartStr)
- Else
- pEnd = pEnd + 1
- FindMirrorString = FindMirrorString + pENum
- str = RightStr(str, EndStr)
- End If
- Loop
- End FunctionPublic Function SplitMTextString(ByVal str As String, ByVal StartStr As String, ByVal EndStr As String) As Collection
- On Error Resume Next
- Dim pStr As String
- Dim pStrs As New Collection
- Dim pStart As Integer
- Dim pEnd As Integer
- Dim pNum As Integer
- pNum = FindStr(str, StartStr)
- If pNum = 0 Then
- GoTo EndHandle
- ElseIf pNum > 1 Then
- pStrs.Add LeftStr(str, StartStr)
- str = "{" & RightStr(str, StartStr)
- End If
- pNum = 1
- Do While pNum > 0
- pStart = pNum
- pEnd = FindMirrorString(str, StartStr, EndStr)
- If FindStr(str, StartStr) > 0 Then pStrs.Add LeftStr(str, StartStr)
- pStr = Mid(str, pStart + 1, pEnd - pStart - 1)
- For Each i In SplitMTextString(pStr, StartStr, EndStr)
- pStrs.Add i
- Next i
- Err.Clear
- str = Right(str, Len(str) - pEnd)
- pNum = FindStr(str, StartStr)
- Loop
- EndHandle:
- pStrs.Add str
- Set SplitMTextString = pStrs
- End FunctionPublic Function SplitRtfString(ByVal str As String) As Collection
- Dim pSplit As Variant
- Dim pStr As String
- Dim pStrs As New Collection
- Dim i As Integer
- If str = "" Then GoTo EndHandle
- str = "L" & str
- pSplit = Split(str, "")
- i = 0
- Do While i <= UBound(pSplit)
- If pSplit(i) = "" Then
- If pStrs.Count > 0 Then
- pStr = pStrs(pStrs.Count)
- pStrs.Remove pStrs.Count
- End If
- pStrs.Add pStr & "" & pSplit(i + 1)
- i = i + 1
- ElseIf Asc(pSplit(i)) = 123 Or Asc(pSplit(i)) = 125 Then
- If pStrs.Count > 0 Then
- pStr = pStrs(pStrs.Count)
- pStrs.Remove pStrs.Count
- End If
- pStrs.Add pStr & pSplit(i)
- Else
- pStrs.Add pSplit(i)
- End If
- i = i + 1
- Loop
- EndHandle:
- Set SplitRtfString = pStrs
- End Function
- Public Function GetMTextString(str As String) As String
- Dim pStr As String, pType As Long
- Dim i, j
-
- For Each i In SplitMTextString(str, "{", "}")
- For Each j In SplitRtfString(i)
- If CStr(UCase(Left(j, 1))) <> "" Then
- pType = Asc(CStr(UCase(Left(j, 1))))
- Select Case pType
- Case 65, 67, 70, 72, 81, 84, 87 'A/C/F/H/Q/T/W
- pStr = pStr & RightStr(j, ";")
- Case 76, 79, 80 'L/O/P
- pStr = pStr & RightStr(j, Left(j, 1))
- Case 83 'S
- j = Mid(j, 2, Len(j) - 2)
- pStr = pStr & Replace(j, "^", "")
- Case 85 'U
- pStr = pStr & "" & j
- Case 126 '~
- pStr = pStr & Replace(j, "~", " ")
- Case Else
- pStr = pStr & j
- End Select
- End If
- Next j
- Next i
-
- GetMTextString = pStr
- End Function
|
评分
-
参与人数 1 | 威望 +1 |
金钱 +10 |
贡献 +5 |
激情 +5 |
收起
理由
|
mccad
| + 1 |
+ 10 |
+ 5 |
+ 5 |
【精华】好程序 |
查看全部评分
|