title: how to find the number of occurrences of a substring within a string vb.net
body: <p>
  I have a string (for example: <code>"Hello there. My name is John. I work very hard. Hello there!"</code>) and I am trying to find the number of occurrences of the string <code>"hello there"</code>. So far, this is the code I have:</p>
  
  <pre class="lang-vb.net prettyprint-override"><code>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
  </code></pre>
  
  <p>Unfortunately, what this line of code seems to do is split the string every time it sees the first letter of <code>phrase</code>, in this case, <code>h</code>. So instead of the result <code>Occurrences = 2</code> 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?</p>