Re: case-insensitive but case-ordered sort
Re: case-insensitive but case-ordered sort
- Subject: Re: case-insensitive but case-ordered sort
- From: Charlie Dickman <email@hidden>
- Date: Tue, 20 Jul 2010 14:04:57 -0400
You should be able to accomplish what you want using NSPredicate.
You can also use the C functions topper and tolower to detect and distinguish case differences.
On Jul 20, 2010, at 1:39 PM, Roland King wrote:
> I want to sort some NSStrings in such a way that words group case insensitively, but within that group lowercase comes first, effectively I want the sort order of letters to be
>
> aAbBcCdDeEfF .. etc with everything outside the letter space sorting 'naturally' and coming after the letters (I actually don't care too much about the last bit honestly they can go where they like as long as it's outside the alphabet range).
>
> so
>
> myClass comes before
> MyClass which comes before
> yourClass which comes before
> YourClass
>
> First off is there a defined sort routine in or around NSString which does something like this (I found a kCFCompareForcedOrdering flag in CFString which seems to do something similar, but possibly backwards from what I want). I can restrict the domain to ASCII without any real issues but if there's something which is localized, that would be better.
>
> I thought perhaps that comparing the two strings case insensitively, returning that compare if they are not equal, but if they are equal, comparing them case sensitively and returning the inverse of that (remember I want a to beat A) would do what I want but I've failed to convince myself that actually works.
>
> Is there an NSString or CFString method I should be looking at or am I off to roll my own? _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
Charlie Dickman
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden