Re: NSString's compare:options: and NSNumericSearch. Huh?
Re: NSString's compare:options: and NSNumericSearch. Huh?
- Subject: Re: NSString's compare:options: and NSNumericSearch. Huh?
- From: Ricky Sharp <email@hidden>
- Date: Sat, 3 Dec 2005 20:46:58 -0600
On Dec 3, 2005, at 6:55 PM, Manfred Schubert wrote:
On Dec 4, 2005, at 1:21 AM, Ricky Sharp wrote:
I just tried the above and in both cases the result is
NSOrderedAscending. My OS (10.4.3) uses US English and Number
Format is also set to US.
OK, I set language and number format to US and rebootet and still
get the wrong result (10.4.3 as well). What could be the reason of
that?
Darn, there was a typo in my sample app. I was about to send you my
sample app offlist, but now I'm also able to reproduce the problem.
What's really strange is that in my app, a custom list control sorts
strings a-ok as your strings come out in this order:
Foo2.txt
Foo7.txt
Foo25.txt
Here's my comparitor which is category of NSString:
- (NSComparisonResult)listItemCompare:(NSString*)anItemName
{
return [self compare:anItemName
options:NSLiteralSearch | NSNumericSearch |
NSCaseInsensitiveSearch];
}
Now, in your example, you're using string literals and my app was
using NSString instances. So, I changed your code to this:
NSString* string1 = [NSString stringWithString:@"Foo2.txt"];
NSString* string2 = [NSString stringWithString:@"Foo7.txt"];
NSString* string3 = [NSString stringWithString:@"Foo25.txt"];
result = [string1 compare:string2 options:NSLiteralSearch |
NSNumericSearch | NSCaseInsensitiveSearch];
NSLog (@"first = %d", result);
result = [string2 compare:string3 options:NSLiteralSearch |
NSNumericSearch | NSCaseInsensitiveSearch];
NSLog (@"second = %d", result);
And it works! You get NSOrderedAscending in both cases.
So, it appears that one cannot use compare:options: (perhaps any of
the compare: APIs?) against string literals. Someone may be able to
explain why.
___________________________________________________________
Ricky A. Sharp
mailto:email@hidden
Instant Interactive(tm)
http://www.instantinteractive.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden