jhylands

Count the number of occurences

Dec 28th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.52 KB | None | 0 0
  1.     Function count(ByVal haystack As String, ByVal needle As String) As Integer
  2.         Dim start As Integer = 1 'number of charactors in, in which to start searching from (stops counting the same one)
  3.         Dim total As Integer = 0 'the total number of occurences
  4.         'Count until there are no more
  5.         Do Until InStr(start, haystack, needle) = 0
  6.             start = InStr(start, haystack, needle) + 1
  7.             total = total + 1
  8.         Loop
  9.         'return the value
  10.         Return total
  11.     End Function
Advertisement
Add Comment
Please, Sign In to add comment