Question: I have a string (for example: `"Hello there. My name is John. I work very hard. Hello there!"`) and I am trying to find the number of occurrences of the string `"hello there"`. So far, this is the code I have:

```vb.net
Dim input as String = "Hello there. My name is John. I work very hard. Hello there!"
Dim phrase as String = "hello there"
Dim Occurrences As Integer = 0

If input.toLower.Contains(phrase) = True Then
    Occurrences = input.Split(phrase).Length      
    'REM: Do stuff
End If

```

Unfortunately, what this line of code seems to do is split the string every time it sees the first letter of `phrase`, in this case, `h`. So instead of the result `Occurrences = 2` that I would hope for, I actually get a much larger number. I know that counting the number of splits in a string is a horrible way to go about doing this, even if I did get the correct answer, so could someone please help me out and provide some assistance?

Answer: 
Yet another idea:

```
Dim input As String = "Hello there. My name is John. I work very hard. Hello there!"
Dim phrase As String = "Hello there"
Dim Occurrences As Integer = (input.Length - input.Replace(phrase, String.Empty).Length) / phrase.Length

```

You just need to make sure that `phrase.Length > 0`.
One more solution based on `InStr(i, str, substr)` function (searching `substr` in `str` starting from `i` position, [more info about InStr()](https://www.w3schools.com/asp/func_instr.asp)):

```
Function findOccurancesCount(baseString, subString)
    occurancesCount = 0
    i = 1
    Do
        foundPosition = InStr(i, baseString, subString) 'searching from i position
        If foundPosition > 0 Then                       'substring is found at foundPosition index
            occurancesCount = occurancesCount + 1       'count this occurance
            i = foundPosition + 1                       'searching from i+1 on the next cycle
        End If
    Loop While foundPosition <> 0
    findOccurancesCount = occurancesCount
End Function

```

As soon as there is no substring found (`InStr` returns `0`, instead of found substring position in base string), searching is over and occurances count is returned.