|
-
July 3rd, 2008, 07:39 AM
#2
Re: MFC STL: How can I sort a 'CArray' (or 'CStringArray', 'CIntArray', etc.)?
One alternative solution is to use the ANSI C function qsort
Next example sorts ascending, non case-sensitive the elements of a CStringArray.
Code:
CStringArray arr;
arr.Add(_T("barbu")); // just for example
arr.Add(_T("ANNA"));
arr.Add(_T("ZOE"));
arr.Add(_T("BUBU"));
arr.Add(_T("bob"));
arr.Add(_T("MIKI"));
// ...
qsort(arr.GetData(), arr.GetSize(), sizeof(CString*), CompareAscNoCase);
Code:
int CompareAscNoCase(const void* left, const void* right)
{
return ((CString*)left)->CompareNoCase(*((CString*)right));
}
Last edited by ovidiucucu; July 3rd, 2008 at 07:42 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|