title: Selecting text in vb
body: <p>I want to select a word to another word in a text box in vb.net with everything between them highlighted. </p>
  
  <p>an example is </p>
  
  <blockquote>
    <p>I went to the beach, had a pinic with my family and then went home at 6 o clock.</p>
  </blockquote>
  
  <p>The starting word to be <code>had</code> and the end word being <code>home</code> and everything highlighted in between. </p>
  
  <p>I have already used a little bit of code </p>
  
  <pre><code>Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
      Dim a As String
      Dim b As String
      a = TextBox2.Text 'means what ever is in textbox2 string to the location where "a" is
      b = InStr(RichTextBox1.Text, a)
      If b Then
          RichTextBox1.Focus()
          RichTextBox1.SelectionStart = b - 1
          RichTextBox1.SelectionLength = Len(a)
  </code></pre>
  
  <p>but its not exactly what i want it to do. </p>
  
  <p>Addition to this was using RegEx Function  as shown below </p>
  
  <pre><code>  'gets rid of the enter line break eg &lt;enter&gt; command no new lines
       Dim content As String = Replace(TextBox1.Text, Global.Microsoft.VisualBasic.ChrW(10), Nothing)
      'searches for this tag in the brackets between ".*" will be the contents
      Dim Regex As New Regex("&lt;div.*class=""answer_text"".*id=editorText"".*""")
      'Show the string 
      For Each M As Match In Regex.Matches(content)
      'This will get the values, there are 3 atm meta.name des and content
      Dim Description As String = M.Value.Split("""").GetValue(3)
      'displays the content in the label
      TextBox3.Text = "" &amp; Description
      Next
  </code></pre>