I've been coding a program that stores student data (name and age) in a .txt file. I am now doing the delete method. However, when the user enters a string, I want it to compare the input to the strings in my List<string>, that's full of names. Code:
string tempFileName;
string inputSel; // Selection string for delete
Console.WriteLine(" -- Deleting Grade {0} -- ", grade);
Console.WriteLine("- Enter a student name to delete: ");
foreach (string file in fileNames)
{
tempFileName = file.Replace(".txt", "");
studentNames.Add(tempFileName);
}
foreach (string name in studentNames)
{
Console.Write("{0}\n", name);
}
Console.WriteLine();
Console.Write("> ");
inputSel = Console.ReadLine();
string input = inputSel.ToLower();
string tempString;
bool foundString = false;
foreach (string file in studentNames)
{
tempString = file.ToLower();
if (inputSel == tempString)
{
foundString = true;
}
}
if (!foundString)
{
Console.WriteLine("Wrong name entered!");
Console.WriteLine("Returning to grades menu..");
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
return;
}
As you can see, the program stores inputSel into input (ToLower()), then compares each string in studentNames List<string>, and if it finds a match it flips the foundString bool, but even if I enter a name that matches (for example, it says JacobMusterson, I enter JacobMusterson, it should skip the "student not found", but it doesn't.