title: Count the number of the same words in richtextbox
body: <p>I want to count the words in richtextbox. First, i input a word in textbox1(for searching), and press "count" button, textbox2 will show a number about how many the same words in the richtextbox.  Here are my codes, but it doesn't work, the textbox2 always shows 0.Thank you for your help. </p>
  
  <pre><code>      private void button2_Click(object sender, EventArgs e)
     {
       string a=richTextBox1.Text;
       string b=textBox1.Text;
  
       for (int i = 0; i &lt; a.Length; i++)
       {
  
          int n=0;
  
          if (a.Equals(b))
          {
  
            n++;
  
          }
  
          textBox2.Text = n.ToString();
  
       }
  
    }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/0wXVE.jpg" alt="enter image description here"></p>