码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 汉字转拼音

时间:2016-09-26 17:45:16      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

- (NSString *)getFirstString:(ICCustom *)custom {
    NSMutableString *source = [custom.merchantAbbreviation mutableCopy];
    if(source && custom.merchantAbbreviation.length>0)
    {
        CFRange range = CFRangeMake(0, 1);
        CFStringTransform((__bridge CFMutableStringRef)source, &range, kCFStringTransformMandarinLatin, NO);
        CFStringTransform((__bridge CFMutableStringRef)source, &range, kCFStringTransformStripDiacritics, NO);
        NSString *phonetic = source;
        phonetic = [phonetic substringToIndex:1];
        phonetic = [phonetic uppercaseString];
        int temp = [phonetic characterAtIndex:0];
        if (temp < 65 || temp > 122 || (temp > 90 && temp < 97)) {
            //不合法的title
            phonetic = @"#";
        }else{
            phonetic = phonetic;
        }
        return phonetic;
    }else
    {
        return @"#";
    }
}

iOS 汉字转拼音

标签:

原文地址:http://www.cnblogs.com/tian-sun/p/5909918.html

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