函数名称:
1、ParameterValue()
2、ParameterCount()
用法示例:
Dim StrTest as String
StrTest="欢迎;光临;JiaJia;Blog;VB源码"
Debug.Print ParameterCount(";",StrTest)
'返回 5
Debug.Print ParameterValue(";",StrTest,3)
'返回 "JiaJia"
函数源码:
Public Function ParameterCount(ParseCharacter As String, _
tString As Variant) As Integer
Dim CurrentPosition As Integer
Dim ParseToPosition As Integer
Dim CurrentToken As Integer
Dim TempString As String
TempString = Trim(tString) + ParseCharacter
If Len(TempString) = 1 Then Exit Function
CurrentPosition = 1
CurrentToken = 1
Do
ParseToPosition = InStr(CurrentPosition, TempString, _
ParseCharacter)
CurrentToken = CurrentToken + 1
CurrentPosition = ParseToPosition + 1
Loop Until (CurrentPosition >= Len(TempString))
ParameterCount = CurrentToken - 1
End Function
Public Function ParameterValue(ParseCharacter As String, _
tString As Variant, _
Index As Integer) As String
Dim CurrentPosition As Integer
Dim ParseToPosition As Integer
Dim CurrentToken As Integer
Dim TempString As String
TempString = Trim(tString) + ParseCharacter
If Len(TempString) = 1 Then Exit Function
CurrentPosition = 1
CurrentToken = 1
Do
ParseToPosition = InStr(CurrentPosition, TempString, _
ParseCharacter)
If Index = CurrentToken Then
ParameterValue = Mid$(TempString, CurrentPosition, _
ParseToPosition - CurrentPosition)
Exit Function
End If
CurrentToken = CurrentToken + 1
CurrentPosition = ParseToPosition + 1
Loop Until (CurrentPosition >= Len(TempString))
End Function
目前有0条回应
Comment
Trackback