Date
Jul. 14th, 2024
 
2024年 6月 9日

Post: iOS 小知识: 汉字转拼音

iOS 小知识: 汉字转拼音

Published 12:10 Oct 14, 2014.

Created by @ezra. Categorized in #Programming, and tagged as #iOS.

Source format: Markdown

Table of Content

介绍一些 iOS 小知识。

汉字转拼音

@interface NSString (MandarinLatin)
- (NSString *)stringByReplacingMandarinToLatinWithDiacritics:(BOOL)diacritics firstLetterCapitalizes:(BOOL)capitalizes;
@end

@implementation NSString (MandarinLatin)
- (NSString *)stringByReplacingMandarinToLatinWithDiacritics:(BOOL)diacritics firstLetterCapitalizes:(BOOL)capitalizes {
    NSMutableString *original = [NSMutableString stringWithString:self];
    // 转换为带变声符的拼音
    CFStringTransform((CFMutableStringRef)original, NULL, kCFStringTransformMandarinLatin, NO);
    if (!diacritics) {
        // 去除变音符
        CFStringTransform((CFMutableStringRef)original, NULL, kCFStringTransformStripDiacritics, NO);
    }

    if (capitalizes) {
        return [original capitalizedString];
    } else {
        return [original copy];
    }
}
@end
Pinned Message
HOTODOGO
I'm looking for a SOFTWARE PROJECT DIRECTOR / SOFTWARE R&D DIRECTOR position in a fresh and dynamic company. I would like to gain the right experience and extend my skills while working in great teams and big projects.
Feel free to contact me.
For more information, please view online résumé or download PDF
本人正在寻求任职 软件项目经理 / 软件技术经理 岗位的机会, 希望加⼊某个新鲜⽽充满活⼒的公司。
如有意向请随时 与我联系
更多信息请 查阅在线简历下载 PDF