C
C#17mo ago
The Joker

❔ Help with StreamReader txt file

hello everybody! I'm trying to do a reading inside a .txt file, at first I type a name in a textbox when I give the command that name would be searched inside the .txt file and if it found the name it will be deleted, does anyone have any idea how do that?
private void btnDelete_Click(object sender, EventArgs e)
{
string path = @"ADDONS\Favorites.txt";
StreamReader fav = new StreamReader(path);

string[] lines = File.ReadAllLines(fav.ToString());

foreach (string line in lines)
{
if(line.ToString() == textbox1.Text.ToString())
{
line.Replace(line, "");
}
}
fav.Close();
}
private void btnDelete_Click(object sender, EventArgs e)
{
string path = @"ADDONS\Favorites.txt";
StreamReader fav = new StreamReader(path);

string[] lines = File.ReadAllLines(fav.ToString());

foreach (string line in lines)
{
if(line.ToString() == textbox1.Text.ToString())
{
line.Replace(line, "");
}
}
fav.Close();
}
3 Replies
TheBoxyBear
TheBoxyBear17mo ago
Your best bet is to go through the file and rewerite it
TheBoxyBear
TheBoxyBear17mo ago
Stack Overflow
How to delete a line from a text file in C#?
I have a problem: how can I delete a line from a text file in C#?
Accord
Accord17mo ago
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.