码迷,mamicode.com
首页 > 编程语言 > 详细

中文排序问题

时间:2015-10-28 14:07:43      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSArray* array = @[ @"北京", @"广州", @"上海", @"西安", @"安徽" ];
    NSArray* sortArray = [array sortedArrayUsingComparator:^NSComparisonResult(NSString* obj1, NSString* obj2) {
        
        CFMutableStringRef string1 = CFStringCreateMutableCopy(NULL, 0,  (__bridge CFStringRef)obj1);
        
        CFStringTransform(string1, NULL, kCFStringTransformMandarinLatin, NO);
        CFStringTransform(string1, NULL, kCFStringTransformStripDiacritics, NO);
        
        CFMutableStringRef string2 = CFStringCreateMutableCopy(NULL, 0, (__bridge CFStringRef)obj2);
        CFStringTransform(string2, NULL, kCFStringTransformMandarinLatin, NO);
        CFStringTransform(string2, NULL, kCFStringTransformStripDiacritics, NO);
        
        NSString *str1 = (__bridge NSString *)string1;
        NSString *str2 = (__bridge NSString *)string2;
        

        NSComparisonResult  result =  [str1 compare:str2 ];
        CFRelease(string1);
        CFRelease(string2);
        return result;
        
    }];
    
    NSLog(@"%@",sortArray);
}

 

中文排序问题

标签:

原文地址:http://www.cnblogs.com/gaox97329498/p/4917035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!