|
|
Function GetPart(strInput As String, Spil As String, Part As Integer) As String
Dim StartPos As Integer, EndPos As Integer, tmpstr As String, SpilCount As Integer
Dim i As Integer, j As Integer
tmpstr = strInput
SpilCount = 0
For i = 1 To Len(tmpstr)
If Mid(tmpstr, i, 1) = Spil Then SpilCount = SpilCount + 1
Next i
If Part > SpilCount Then
For i = 1 To Part - SpilCount
tmpstr = tmpstr + Spil
Next i
End If
EndPos = 0
For i = 1 To Part
StartPos = EndPos + 1
EndPos = InStr(StartPos, tmpstr, Spil, vbTextCompare)
Next i
GetPart = Mid(tmpstr, StartPos, EndPos - StartPos)
End Function
这个函数的作用很容易看出来吧,就是把一个语句的各个参数读出来,比如说:
s = "C:\Command.com,1"
GetPart(s,",",1)就可以得到s这个字符串中以","为分隔符的第一个参数"C:\Command.com"。 |
|