|

楼主 |
发表于 2012-1-16 22:36:36
|
显示全部楼层
随手写了一下,几个简单的测试,没发现问题。- Option Explicit
- Private Enum emState
- c_Init
- c_Slash
- c_NonSlash
- End Enum
- Private Function TransStr(s As String) As String
- Dim t As String
- Dim i As Byte
- Dim Ch As String
- Dim st As emState
-
- st = c_Init
- t = ""
-
- For i = 1 To Len(s)
- Ch = Mid(s, i, 1)
- Select Case st
- Case c_Init
- If Ch = "" Then
- st = c_Slash
- Else
- st = c_NonSlash
- End If
- t = t & Ch
- Case c_Slash
- If Ch <> "" Then
- st = c_NonSlash
- t = t & Ch
- End If
- Case c_NonSlash
- If Ch = "" Then
- st = c_Slash
- End If
- t = t & Ch
- End Select
- Next i
-
- TransStr = t
- End Function
- Private Sub Form_Load()
- Debug.Print TransStr("C:\abc\\\def\\ghijk\lmn\\\\opq\rs\\\\")
- Unload Me
- End Sub
复制代码 输出:
C:\abc\def\ghijk\lmn\opq\rs\ |
|