Hello, I'm having problems removing an array of lines from a text file.

Heres my code:

Ugh, I apologize. I can't get the conventions to correctly show on this post, I'm really sorry.

using (var sr = new StreamReader(Misc.tempFile))
{
	using (var sw = new StreamWriter(Misc.path + "test.dat"))
	{
		while ((line = sr.ReadLine()) != null)
		{
			for (int i = 0; i < detailViewer.SelectedIndices.Count; i++)
			lineToDelete[i] = Encryption.encrypt(detailViewer.SelectedItems[i].SubItems[0].Text) +
			"," + Encryption.encrypt(detailViewer.SelectedItems[i].SubItems[1].Text) + ","
			+ Encryption.encrypt(detailViewer.SelectedItems[i].SubItems[2].Text);
			if (line != lineToDelete[detailViewer.SelectedIndices.Count - 1] && !line.StartsWith("/"))
			sw.WriteLine(line);
		}
	}
}

I'm using the listview component, and basically all the lines from the text file are listed in the listview box. You select a number of lines, then you can delete them.

It works fine but it doesn't delete all the selected lines. I've tried using a loop on the line check, but all that does it duplicate the lines. Please help me.

Sorry, my post was a recommendation, you didn't need to repost your code this time. Try to avoid posting duplicate questions as it results in the help you get being split and its harder to keep track of where you are at. As I've posted some advise on the other thread, mark this as solved and stick to the original one :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.