Compare strings for localization

What is the difference between NSString localizedCaseInsensitiveCompare:and methods localizedStandardCompare:?

I read the link, but did not get the correct idea of ​​which one to use.

+3
source share
3 answers

localizedCaseInsensitiveCompare: equivalent to:

[aString compare:otherString
         options:NSCaseInsensitiveSearch
         range:NSMakeRange(0,aString.length)
        locale:[NSLocale currentLocale]];

localizedStandardCompare: basically equivalent to:

[aString compare:otherString
         options:NSCaseInsensitiveSearch | NSNumericSearch
         range:NSMakeRange(0,aString.length)
        locale:[NSLocale currentLocale]];

So, the main difference is how the numbers inside the strings are compared.

Comparing the following three lines using localizedCaseInsensitiveCompare:will result in the following order:

"Foo2.txt",
"Foo25.txt",
"Foo7.txt"

On the other hand, comparing them using localizedStandardCompare:will lead to the following order:

"Foo2.txt",
"Foo7.txt",
"Foo25.txt"

localizedCaseInsensitiveCompare: , localizedStandardCompare: (OS X 10.6). Finder , localizedStandardCompare: , , Finder.

, , , , , localizedStandardCompare:.

+8

Finder OS X.

0

localizedCaseInsensitiveCompare: localizedCompare:

NSComparisonResult, , .

, case insensitive. .

localizedStandardCompare This compares rows sorted using the Finder application.

0
source

All Articles