先读入文件全部内容至StrMsg中
此为取出第N条的方法:
StrN=GetItem(StrMsg, vbcrlf & vbcrlf & " " , N)
Function GetItem(Msg As String, ByVal Split As String, ByVal Index As Long, Optional ByVal ByValue As Boolean) As Variant
'取Msg字串中以Split分隔的第Index项
'Index = -1 , Get Items Count
Dim SplitLen As Long
Dim S As Long
Dim N As Long
Dim Count As Long
Dim Item As String
SplitLen = Len(Split)
If Len(Msg) * SplitLen > 0 Then '有效的字符串和分隔符
S = 1
If Index < 0 Then '取项数
Do
N = InStr(S, Msg, Split)
Count = Count + 1
If N > 0 Then S = N + SplitLen
Loop Until (N = 0)
GetItem = Count
Else '取指定项
Do
N = InStr(S, Msg, Split)
If Count = Index Then
Item = Mid(Msg, S, IIf(N = 0, Len(Msg), N - S))
Exit Do
Else
Count = Count + 1
If N > 0 Then S = N + SplitLen
End If
Loop Until (N = 0)
GetItem = IIf(ByValue, Val(Item), Item)
End If
End If
End Function
此为取出第N条的方法:
StrN=GetItem(StrMsg, vbcrlf & vbcrlf & " " , N)
Function GetItem(Msg As String, ByVal Split As String, ByVal Index As Long, Optional ByVal ByValue As Boolean) As Variant
'取Msg字串中以Split分隔的第Index项
'Index = -1 , Get Items Count
Dim SplitLen As Long
Dim S As Long
Dim N As Long
Dim Count As Long
Dim Item As String
SplitLen = Len(Split)
If Len(Msg) * SplitLen > 0 Then '有效的字符串和分隔符
S = 1
If Index < 0 Then '取项数
Do
N = InStr(S, Msg, Split)
Count = Count + 1
If N > 0 Then S = N + SplitLen
Loop Until (N = 0)
GetItem = Count
Else '取指定项
Do
N = InStr(S, Msg, Split)
If Count = Index Then
Item = Mid(Msg, S, IIf(N = 0, Len(Msg), N - S))
Exit Do
Else
Count = Count + 1
If N > 0 Then S = N + SplitLen
End If
Loop Until (N = 0)
GetItem = IIf(ByValue, Val(Item), Item)
End If
End If
End Function
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货