Answer the question
In order to leave comments, you need to log in
Working with files, how to remove a line from a txt file?
private void buttonDeleteCar_Click(object sender, EventArgs e)
{
string[] database = File.ReadAllLines("database.txt");
int len = database.Count();
string deletename = textBoxDeleteName.Text;
for (int i = 0; i < len; i++)
{
string line = database[i];
string[] linemas = line.Split('|');
string name = linemas[1];
if (name == deletename) database[i] = ""; // Сравнение введенного текста с названием авто
}
StreamWriter del = new StreamWriter("database.txt", true);
for (int i = 0; i < database.Count(); i++)
{
del.WriteLine(database[i]);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question