So I have been working on a small project (Previously built with vb.net) in C# ( Being honest, I have used an online vb.net to c# converter to get to this point.) that will basically rename the suffix of a set of files to specific predetermined names (hard coded).
Firstly the working part...
Press button_1, a file dialogue opens and you select files. These are then populated into a listbox_1.
Now press button_2 and the files from listbox_1 are renamed and sent to listbox_2.
Now the issue I am having...
For some reason I cannot figure out, the names are not being changed through the switch statement, they are just taking the string variable name and populating listbox_2 with blank entries (Because the starting Variable is empty).
string NewFileName = "";
I'm not sure what is happening here at all so if anyone is able to help me out that would be great.
private string GetNewName(string OriginalFileName)
{
string NewFileName = "";
switch (true)
{
case object _ when OriginalFileName.Contains(".0001"):
{
NewFileName = OriginalFileName.Replace(".0001", "APPLE");
break;
}
case object _ when OriginalFileName.Contains(".0002"):
{
NewFileName = OriginalFileName.Replace(".0002", "PEAR");
break;
}
}
return NewFileName;
}
private void BTN_ProcessNames_Click(object sender, EventArgs e)
{
foreach (Tuple<string, string> t in listbox_1.Items)
{
var NewName = GetNewName(t.Item2);
listbox_2.Items.Add(NewName);
}
}