iOS Mac OS X system programming to achieve Chinese pinyin transfer method (super simple)
- 2020-05-09 19:22:19
- OfStack
The network popular Chinese characters turn pinyin scheme is to take a pinyin code table, the speed is fast. In fact, Core Foundation also offers a solution with a tone!
NSMutableString *ms = [[NSMutableString alloc] initWithString:@" I'm Chinese "];
if (CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformMandarinLatin, NO)) {
NSLog(@"Pingying: %@", ms); // w ǒ sh i. zh not ng gu o r e n
}
if (CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformStripDiacritics, NO)) {
NSLog(@"Pingying: %@", ms); // wo shi zhong guo ren
}
If you are interested, you can try 1. This function not only supports Chinese, Japanese and Korean, but also is very powerful.