Hi dnnyobi,
Check this example. Now please take its reference and correct your code.
Code
C#
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.Text = "Writing about yourself can seem embarrassing at first. " +
"Cover letters, personal essays, and bio notes about yourself come with some " +
"specific tricks and tips that can make it a lot less intimidating when choosing style and content. " +
"Learn the basics and you will be able to make your personal writing stand out";
txtWord.Text = "and";
}
private void btnCount_Click(object sender, EventArgs e)
{
for (int i = 0; i < richTextBox1.TextLength; i++)
{
richTextBox1.Find(txtWord.Text.Trim(), i, RichTextBoxFinds.WholeWord);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectionBackColor = Color.Yellow;
}
int count = 0;
for (int i = 0; i < richTextBox1.Text.Split(' ').Length; i++)
{
if (richTextBox1.Text.Split(' ')[i].Trim().ToLower() == txtWord.Text.Trim())
{
count = count + 1;
}
}
lblCount.Text = count.ToString();
}
VB.Net
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
richTextBox1.Text = "Writing about yourself can seem embarrassing at first. " +
"Cover letters, personal essays, and bio notes about yourself come with some " +
"specific tricks and tips that can make it a lot less intimidating when choosing style and content. " +
"Learn the basics and you will be able to make your personal writing stand out"
txtWord.Text = "and"
End Sub
Private Sub btnCount_Click(sender As System.Object, e As System.EventArgs) Handles btnCount.Click
For i = 1 To richTextBox1.TextLength
richTextBox1.Find(txtWord.Text.Trim(), i, RichTextBoxFinds.WholeWord)
richTextBox1.SelectionColor = Color.Red
richTextBox1.SelectionBackColor = Color.Yellow
Next
Dim count As Integer
For i = 1 To richTextBox1.Text.Split(" ").Length - 1
If richTextBox1.Text.Split(" ")(i).Trim().ToLower() = txtWord.Text.Trim() Then
count = count + 1
End If
Next
lblCount.Text = count.ToString()
End Sub
Screenshot