Filter list data

Source: Internet
Author: User

/*
Filter list data
The source list can be empty or the same as the source list. In this case, only the target list can be deleted without matching the source list.
If the target list and source list addresses are different, the matching Character List is extracted from the source list.
*/
Int filter_list (clistbox * pdstlist, // target list
Clistbox * psrclist, // source list
Lpctstr pszfilter, // match characters
Bool bmatchcase // case-insensitive indication
)
{
Assert (pdstlist); // make sure the list address is valid

If (psrclist & psrclist! = Pdstlist) // the target list and source list address are not the same
{
Pdstlist-> resetcontent (); // clear the list
For (INT I = 0; I <psrclist-> getcount (); I ++)
{
Cstring itemstr;
Psrclist-> gettext (I, itemstr );
Pdstlist-> addstring (itemstr); // Add a string
Pdstlist-> setitemdata (I, psrclist-> getitemdata (I); // copy attributes
}
}

Cstring filter = pszfilter;
Int filter_len = filter. getlength ();
If (filter_len> 0 &&! Bmatchcase) // case insensitive
Filter. makeupper ();

If (strlen (pszfilter)> 0) // The length of the matched string is greater than 0.
{
For (INT I = 0; I <pdstlist-> getcount (); I ++)
{
Cstring itemstr;
Pdstlist-> gettext (I, itemstr );
If (! Bmatchcase)
Itemstr. makeupper ();
If (itemstr. getlength ()> = filter_len
& Itemstr. Left (filter_len) = filter)
{
}
Else // Delete if no match exists
{
Pdstlist-> deletestring (I );
I --; // ensure that the next time the list is deleted
}
}
}

Return (pdstlist-> getcount ());
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.