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.