tags.db
Code:
asd||$|blah
qwe||$|jack daniels
zxc||$|exam
qaz||$|fail
checkedListBox1 items
Code:
if(checkedListBox1->CheckedItems->Count != 0)
{
String ^ line, ^ toDelete;
array<String^>^ seperator = {"||$|"}, ^ seperator2 = {"|$|"}, ^ tag, ^ delete;
for each(line in IO::File::ReadLines("tags.db"))
{
tag = line->String::Split(seperator, StringSplitOptions::None);
// Why this way? If I remove x++, it become's infinite loop
for(int x = 0; x <= checkedListBox1->CheckedItems->Count-1; x++)
{
Object^ checked = checkedListBox1->CheckedItems[0];
if (tag[0] == checked->ToString())
{
toDelete = String::Concat(toDelete, tag[0],"|$|");
checkedListBox1->Items->Remove(checkedListBox1->CheckedItems[0]);
} else {
toDelete = String::Concat(toDelete, " ","|$|");
}
}
delete = toDelete->String::Split(seperator2, StringSplitOptions::RemoveEmptyEntries);
Array::Sort(delete);
if(Array::BinarySearch(delete, tag[0]) < 1)
{
IO::File::AppendAllText("tags.db.temp", line+"\n");
} else {
IO::File::AppendAllText("tags.db.temp","");
}
}
IO::File::Copy("tags.db.temp", "tags.db", true);
IO::File::Delete("tags.db.temp");
}
Supposed to do:
Checked items are NOT included when writing to .temp file (includes only line from .db file which are not checked).
(1) In this, if I check ONLY 1st OR 1st and 1 more item from checkedListBox1: unable to exclude 1st line.
(2) If I check first item and 2 others (or more, all), lines are excluded.
In case only 1 item is left in checkedListBox1, I'm back to (1). =/