开发者

How to compare A to Á on the iPhone

开发者 https://www.devze.com 2023-01-30 16:31 出处:网络
I need to compare 2 strings, looking at the first letter only. Is the开发者_运维问答re a method to compare A to Á, and recognize it as A, without the ´?NSString has a diacritic-insensitive comparis

I need to compare 2 strings, looking at the first letter only.

Is the开发者_运维问答re a method to compare A to Á, and recognize it as A, without the ´?


NSString has a diacritic-insensitive comparison mode which will do what you're after.

// should return NSOrderedSame, i.e. identical
[@"Apple" compare:@"Ápple" 
          options:NSDiacriticInsensitiveSearch]

If you want it to be case-insensitive as well:

// ditto
[@"APPLE" compare:@"Ápple" 
          options:NSDiacriticInsensitiveSearch | NSCaseInsensitiveSearch] 
0

精彩评论

暂无评论...
验证码 换一张
取 消