❔ how do I select a specific text from the file and delete it and it's corresponding contents in C
static void Cancel()
{
StreamReader customercancel = new StreamReader("customerdetails.txt");
while(customercancel.EndOfStream == false)
{
string line = customercancel.ReadLine();
Console.WriteLine(line);
}
//customercancel.Close();
Console.Write("Select the name you want to cancel the appointment");
string namecancel = Console.ReadLine();
File.ReadLines("customerdetails.txt")
.SkipWhile(line => !line.Contains(namecancel))
.Skip(1)
.TakeWhile(line => !line.Contains(namecancel));
}
static void Staff()
{
StreamReader staffavailability = new StreamReader("staff1.txt");
for (int i = 0; i < 10; i++)
{
string line = staffavailability.ReadLine();
Console.WriteLine(line);
}
staffavailability.Close();
}
}
static void Cancel()
{
StreamReader customercancel = new StreamReader("customerdetails.txt");
while(customercancel.EndOfStream == false)
{
string line = customercancel.ReadLine();
Console.WriteLine(line);
}
//customercancel.Close();
Console.Write("Select the name you want to cancel the appointment");
string namecancel = Console.ReadLine();
File.ReadLines("customerdetails.txt")
.SkipWhile(line => !line.Contains(namecancel))
.Skip(1)
.TakeWhile(line => !line.Contains(namecancel));
}
static void Staff()
{
StreamReader staffavailability = new StreamReader("staff1.txt");
for (int i = 0; i < 10; i++)
{
string line = staffavailability.ReadLine();
Console.WriteLine(line);
}
staffavailability.Close();
}
}
2 Replies
string path = @"...";
string line = String.Empty;
while((line = reader.ReadLine()) != null)
List<string> lst = File.ReadAllLines("Data.txt")
.Where(arg => !string
.IsNullOrWhiteSpace(arg))
.ToList();
lst.RemoveAll(x => x.Split('.')[0].Equals(name));
File.WriteAllLines(path, lst);
}
string path = @"...";
string line = String.Empty;
while((line = reader.ReadLine()) != null)
List<string> lst = File.ReadAllLines("Data.txt")
.Where(arg => !string
.IsNullOrWhiteSpace(arg))
.ToList();
lst.RemoveAll(x => x.Split('.')[0].Equals(name));
File.WriteAllLines(path, lst);
}
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.