I have a global string variable - "word".
string word = "";
List<Label> labels = new List<Label>();
int amount = 0;
That word is then defined/assigned in the following two functions by parsing a text document (new line delimited)
void MakeLabels()
{
word = GetRandomWord();
char[] chars = word.ToCharArray();
...
}
string GetRandomWord()
{
System.IO.StreamReader myFile = new System.IO.StreamReader(...);
string myString = myFile.ReadToEnd();
string[] words = myString.Split('\n');
Random ran = new Random();
return words[ran.Next(0, words.Length - 1)];
}
And, finally, an event that validates the contents of a textbox against the "word" variable.
private void button2_Click(object sender, EventArgs e)
{
if (textBox2.Text == word)
{
MessageBox.Show(...);
}
else
{
MessageBox.Show(...);
textBox2.Text = "";
textBox1.Focus();
Reset();
}
The problem I'm having is that even when textBox2 is equivalent to "word", I'm receiving the MessageBox related to the else statement. I think it has to do with the "word" variable carrying in the '\n'; meaning that textBox2.Text = apple and word = apple\n, thus the two variables not being equivalent. Any suggestions?