I have a text file in which I add, update and delete data (Contacts). Each contact is in one line. Now when i delete a contact through my application, I am deleting a line in my file (Replacing the contact with a empty string) This is resulting a empty line in between contacts. I don’t want this empty line. This is the piece of code that I wrote:
private void btn_condel_Click(object sender, EventArgs e)
{
bufferedListView1.Items.Clear();
string fileContents = File.ReadAllText("C:\\sample.txt");
string replacedContents = fileContents.Replace(txt_editname.Text + "@" + txt_editno.Text,"");
File.WriteAllText("C:\\sample.txt", replacedContents);
// Rest of the code
What do I need to do to eliminate this empty line while replacing the data in the file.
It looks like the easiest way to fix this would just be to grab the new line: