我在这里得到了这个字符串:\ server \ Documents \ test \\ 954076 我如何检查是否有\第二次以及我如何切断它然后关闭? 所以\ server \ Documents \ test \\ 954076将是\ server \ Documents \ test \ 954076
答案 0 :(得分:1)
这是减少给定字符连续重复的一般解决方案:
Sub RemoveRepetitions(s As String, c As String)
Dim len1 As Long, len2 As Long
Do
len1 = Len(s)
s = Replace(s, c & c, c)
len2 = Len(s)
Loop Until len2 = len1
End Sub
Sub testing()
Dim s As String: s = "\\server\\\\\\Documents\\\\\test\\954076"
RemoveRepetitions s, "\"
Debug.Print s
End Sub
\服务器\文件\测试\ 954076
答案 1 :(得分:1)
如果您担心双重重复,那么它就足够了
Dim strng As String
strng = "\server\Documents\test\\\954076"
strng = Replace(strng, "\\", "\")
如果你想处理multiple
次重复,那么:
Dim strng As String
strng = "\server\Documents\test\\\954076"
Do While Len(strng) - Len(Replace(strng, "\\", "\")) > 0
strng = Replace(strng, "\\", "\")
Loop