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: 
the best way to do it is this: 

```
Public Function countString(ByVal inputString As String, ByVal stringToBeSearchedInsideTheInputString as String) As Integer
    Return System.Text.RegularExpressions.Regex.Split(inputString, stringToBeSearchedInsideTheInputString).Length -1

End Function

```
I used this in Vbscript, You can convert the same to VB.net as well

```
Dim str, strToFind
str = "sdfsdf:sdsdgs::"
strToFind = ":"

MsgBox GetNoOfOccurranceOf( strToFind, str)

Function GetNoOfOccurranceOf(ByVal subStringToFind As String, ByVal strReference As String)
    Dim iTotalLength, newString, iTotalOccCount
    iTotalLength = Len(strReference)
    newString = Replace(strReference, subStringToFind, "")
    iTotalOccCount = iTotalLength - Len(newString)
    GetNoOfOccurranceOf = iTotalOccCount
End Function

```