CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Jan 2011
    Location
    Vilnius/Utena, Lithuania
    Posts
    14

    [RESOLVED] Exclude checked lines from file

    tags.db
    Code:
    asd||$|blah
    qwe||$|jack daniels
    zxc||$|exam
    qaz||$|fail
    checkedListBox1 items
    Code:
    asd
    qwe
    zxc
    qaz
    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). =/
    Last edited by Migeria; January 22nd, 2011 at 04:50 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured