gh0st-sniper
gh0st-sniper
CC#
Created by gh0st-sniper on 1/4/2023 in #help
❔ 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();
}

}
I need the program to search by customer name in the textfile and delete the line and date of appointment. Help would be appreciated
3 replies