J
Jon
I want to count the number of instances of a certain string(delimiter) in
another string. I didn't see a function to do this in the framework (if
there is, please point me to it). If not, could someone let me know if the
method I've used below is efficient or if there is a better way to do it, as
these will be rather large strings I'm searching in. Thanks
Public Shared Function CountDelimiter(ByVal strInput As String, ByVal
strDelimiter As String) As Int32
Dim iStart As Int32, iCount As Int32, iResult As Int32
'Set our vars to base values
iStart = 1
iCount = 0
Do
'iResult becomes the position where delimiter is found. If 0, not
found.
iResult = InStr(iStart, strInput, strDelimiter)
If iResult = 0 Then Exit Do
'Increment our count var for each time it is found
iCount += 1
'Increment our next start position to be the next char after the
currently found position
iStart = iResult + 1
Loop
Return iCount
End Function
another string. I didn't see a function to do this in the framework (if
there is, please point me to it). If not, could someone let me know if the
method I've used below is efficient or if there is a better way to do it, as
these will be rather large strings I'm searching in. Thanks
Public Shared Function CountDelimiter(ByVal strInput As String, ByVal
strDelimiter As String) As Int32
Dim iStart As Int32, iCount As Int32, iResult As Int32
'Set our vars to base values
iStart = 1
iCount = 0
Do
'iResult becomes the position where delimiter is found. If 0, not
found.
iResult = InStr(iStart, strInput, strDelimiter)
If iResult = 0 Then Exit Do
'Increment our count var for each time it is found
iCount += 1
'Increment our next start position to be the next char after the
currently found position
iStart = iResult + 1
Loop
Return iCount
End Function