vba splite的问题,如果分隔符是数量不定的空格要怎么办
比如如何分割下面这个txt,得到那4个数据的数组,谢谢/db2logrootsystem2755/db2log/actlogrootsystem2755...
比如如何分割下面这个txt,得到那4个数据的数组,谢谢
/db2log root system 2755
/db2log/actlog root system 2755 展开
/db2log root system 2755
/db2log/actlog root system 2755 展开
1个回答
展开全部
Function M(Str)
Dim Arr
Dim Reg As Object
Set Reg = CreateObject("Vbscript.Regexp")
With Reg
.Global = True
.Pattern = "\ +"
If .test(Str) Then
M = .Replace(Trim(Str), "|")
Else
M = ""
End If
End With
Set Reg = Nothing
End Function
Function M2(Str)
Dim Arr, MyStr As String
Arr = Split(Str)
For i = 0 To UBound(Arr)
If Len(Arr(i)) <> 0 Then
MyStr = MyStr & "|" & Arr(i)
End If
Next
M2 = Right(MyStr, Len(MyStr) - 1)
End Function
Sub My()
A = "/db2log root system 2755"
MsgBox M(A)
MsgBox M2(A)
End Sub
Dim Arr
Dim Reg As Object
Set Reg = CreateObject("Vbscript.Regexp")
With Reg
.Global = True
.Pattern = "\ +"
If .test(Str) Then
M = .Replace(Trim(Str), "|")
Else
M = ""
End If
End With
Set Reg = Nothing
End Function
Function M2(Str)
Dim Arr, MyStr As String
Arr = Split(Str)
For i = 0 To UBound(Arr)
If Len(Arr(i)) <> 0 Then
MyStr = MyStr & "|" & Arr(i)
End If
Next
M2 = Right(MyStr, Len(MyStr) - 1)
End Function
Sub My()
A = "/db2log root system 2755"
MsgBox M(A)
MsgBox M2(A)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询