Hi @Scott George ,
In order to correctly save the data into your text file, you need to change
File.AppendAllText(@"C:\Users\TSG\source\repos\tsgxcode\OMDB\Data.txt",
("{0}", ".", "{1}", ".", "{2}", ".", "{3}", ".", "{4}", ".",
"{5}", ".", "{6}", ".") + Environment.NewLine);
To
File.AppendAllText(@"test.txt",$"{artist}.{formationDate}.{favoriteAlbum}.{yearOfRelease}.{numberOfSongs}.{genre}" + Environment.NewLine);
Then, you can refer to the following code to removing the certain line from a text file.
public static void removeArtist()
{
Console.Write("Please enter the artist name you want to delete: ");
string name = Console.ReadLine();
List<string> lst = File.ReadAllLines("Data.txt").Where(arg => !string.IsNullOrWhiteSpace(arg)).ToList();
lst.RemoveAll(x => x.Split('.')[0].Equals(name));
File.WriteAllLines("Data.txt", lst);
}
Hope it could be helpful.
Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.