NSStringCompareOptions, Translation

Source: Internet
Author: User

NSStringCompareOptions, Translation

 

TypedefNS_OPTIONS (NSUInteger, NSStringCompareOptions ){

NSCaseInsensitiveSearch = 1, // case-insensitive comparison

NSLiteralSearch = 2, // case-sensitive by byte

NSBackwardsSearch = 4, // search from the end of the string

NSAnchoredSearch = 8, // search for a restricted string

NSNumericSearch = 64, // calculate the order based on the numbers in the string. For example, Foo2.txt <Foo7.txt <Foo25.txt

NSDiacriticInsensitiveSearchNS_ENUM_AVAILABLE (10_5, 2_0) = 128, // ignore the comparison of the "-" symbol

NSWidthInsensitiveSearchNS_ENUM_AVAILABLE (10_5, 2_0) = 256, // ignore the length of the string and compare the result

NSForcedOrderingSearchNS_ENUM_AVAILABLE (10_5, 2_0) = 512, // ignore case-insensitive options, and forcibly return NSOrderedAscending or NSOrderedDescending

Round (10_7, 3_2) = 1024 // it can only be applied to rangeOfString:..., stringByReplacingOccurrencesOfString:... And replaceOccurrencesOfString:... method. If this option is set, NSCaseInsensitiveSearch and NSAnchoredSearch can be removed.

};

 

 

 

NSArray * stringsArray = [NSArrayarrayWithObjects:

@ "String 10 ",

@ "String 1 ",

@ & Quot; string 120 & quot ",

@ & Quot; String 1100 & quot ",

"String 02000", nil];

NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch | NSNumericSearch | NSWidthInsensitiveSearch | NSForcedOrderingSearch;

NSLocale * currentLocale = [NSLocalecurrentLocale];

NSComparator finderSortBlock = ^ (id string1, id string2 ){

Nsange string1Range = NSMakeRange (0, [string1length]);

Return [string1compare: string2options: comparisonOptionsrange: string1Rangelocale: currentLocale];

};

NSArray * finderSortArray = [stringsArraysortedArrayUsingComparator: finderSortBlock];

NSLog (@ "finderSortArray: % @", finderSortArray );

 

 

FinderSortArray :(

"String 1 ",

"String 10 ",

& Quot; string 120 & quot ",

& Quot; String 1100 & quot ",

& Quot; String 02000 & quot"

)

 

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.