I've been coding a program that stores student names and age (First name, last name, age in a .txt file). I am now making the "delete student" part, and when I want the user to select what name to delete (which is printed by cutting off the .txt extension of the filenames), it doesn't replace the ".txt" part with nothing.
The code is:
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)
{
file.Replace(".txt", "");
studentNames.Add(file);
Console.WriteLine(file); // debug
}
foreach (string name in studentNames)
{
Console.Write("{0}\t", name);
}
Console.WriteLine();
Console.Write("> ");
inputSel = Console.ReadLine();
Where fileNames is a List<string>
, it is a parameter for the method this code is in. studentNames is also a List<string>
, where it stores the names (file name without .txt), but it still prints the name with .txt for some reason.
Long story short, it doesn't replace ".txt"
with ""
.