Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim a As String = "me me!@# me"
Dim f As String = "me"
MessageBox.Show(String.Format( _
"'{0}' is contained {1} times in '{2}'.", f, Find(a, f), a))
End Sub
Private Function Find(ByVal MyString As String, ByVal WhatToFind As String) As Integer
Dim times As Integer = 0
Dim _s As String = MyString
While _s.IndexOf(WhatToFind) <> -1
_s = _s.Substring(_s.IndexOf(WhatToFind) + 1)
times += 1
End While
Return times
End Function