Okay, so I'm having trouble. I have a form that has three textboxes and a button, and in the first textbox (textBox1), the user inputs a sentence. In the next textbox (textBox3), the user inputs a word. Then the user clicks a button, and the third textbox (textBox2) checks to see if the word that is input matches a word in the sentence. I can't use any kind of "shortcuts", I can only go about it the long way (no .Compare or anything like that). Here's what I have so far:
private void button1_Click(object sender, EventArgs e)
{
string inSentence = textBox1.Text.ToUpper();
string txtB2 = textBox3.Text.ToUpper();
string[] inWord;
inWord = inSentence.Split(' ');
int wordCount = inWord.Length;
for (int i = 0; i < wordCount; i++)
{
if (txtB2 == inWord[i])
{
textBox2.Text = "Yes";
}
else
textBox2.Text = "No";
}
}
The problem I'm having is that, say if I type "hi its me" in the first box, the only word that will match is "me". It only matches the last word. It's not matching everything.
Again, I can only go about it in a way sort of like this. I just would like to know where I'm going wrong, and why. If anyone can help me, it would be much appreciated.
I've also tried using this
foreach (string n in inWord)
{
textBox2.Text = inWord + " ";
for (int i = 0; i < wordCount; i++)
{
if (txtB2 == n)
{
textBox2.Text = "Yes " + n;
}
else
textBox2.Text = "No " + n;
}
}
And am getting the same problem (I added the "n" to the text output to check what word it will be on and it's always on "ME" when I type in "hi its me").