网络流行的汉字转拼音方案是带一个拼音码表,速度快。其实Core Foundation也提供了一种方案,而且还带声调!
[cpp]
view plain
copy
- NSMutableString
*ms = [[NSMutableString alloc] initWithString:@"我是中国人"]; - if
(CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformMandar inLatin, NO)) { -
NSLog(@"Pingying: %@", ms); // wǒ shì zhōng guó rén - }
- if
(CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformStripD iacritics, NO)) { -
NSLog(@"Pingying: %@", ms); // wo shi zhong guo ren - }