I have a text file that a list of these words on it
Laptop
Laser
Macho
Sam
Samantha
Mulder
Microphone
Aardvark
And what I want to do is have user input type in a word and the console will basically respond with we have your word or we do not have your word. This is my code so far:
TextReader file = new StreamReader("Files/Exercise_Files/Words.txt");
Console.WriteLine("Welcome to FindWord");
string wordInput;
Console.WriteLine("Type in a word so we can try and find it: ");
wordInput = Console.ReadLine();
string sLine = file.ReadToEnd();
if (String.Compare(wordInput, sLine, true) == 0)
{
Console.WriteLine("We have found your word!");
}
else
{
Console.WriteLine("We have not found your word");
}
file.Dispose();
I have tried doing a couple of versions trying to solve this and one included adding a for-each loop but that confused me quite a bit. I'm not 100% sure when to use a for-each loop. I also want to have string comparison be case insensitive but the code I have now will always say word not found no matter what I input.