个字符串处理函数:
1、ParameterValue()
2、ParameterCount()
用法示例:
dim TheString as String
TheString="欢迎,光临,枕善居,源代码"
msgbox ParameterCount(",",TheString)
返回 4
ParameterValue(",",TheString,2)
返回 "欢迎"
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
1、ParameterValue()
2、ParameterCount()
用法示例:
dim TheString as String
TheString="欢迎,光临,枕善居,源代码"
msgbox ParameterCount(",",TheString)
返回 4
ParameterValue(",",TheString,2)
返回 "欢迎"
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