Using CFStringTransform to convert Chinese characters into Pinyin is time consuming !, Cfstringtransform
Recently, in an address book project, you need to read contacts into the app memory (there are about 400 contacts in the address book) and sort them by the first letter. Here we use the built-in iOS system interface when converting Chinese characters into pinyin:
Note that self. latinString must be a mutable string.
// 1. convert a non-string into a Latin letter CFStringTransform (_ bridge CFMutableStringRef) self. latinString, NULL, kCFStringTransformMandarinLatin, NO); CFStringTransform (_ bridge CFMutableStringRef) self. latinString, NULL, kCFStringTransformStripDiacritics, NO );
However, the app is very slow to start. Because the contact is being loaded and the Chinese characters are converted into pinyin. Let's take a look at the comparison results:
If direct conversion:
> 16:14:03. 988 [contact_log] ContactList. m: 87-[ContactList loadcontactfromonoclonal]: _ addressBookEngine loadAdressBook10.022583
It takes 10 seconds to load the file.
My practice is: Since the people in the address book will not change frequently, You Can cache the name of all people-pinyinDic (dictionary). In this way, you can obtain pinyin from the dictionary, it should be much faster! The result proves my conjecture:
// 1. obtain latin from the cache, then determine whether the latin exists, and then convert the non-string into the latin letter NSString * latin = [pinyinDic objectForKey: self. fullName]; if (latin) {self. latinString = latin;} else {CFStringTransform (_ bridge CFMutableStringRef) self. latinString, NULL, kCFStringTransformMandarinLatin, NO); CFStringTransform (_ bridge CFMutableStringRef) self. latinString, NULL, kCFStringTransformStripDiacritics, NO); [pinyinDic setObject: self. latinString forKey: self. fullName];}
The running result is:
> 16:18:47. 992 [contact_log] ContactList. m: 87-[ContactList loadcontactfromonoclonal]: _ addressBookEngine loadAdressBook0.641795
Loading is less than 1 second.
Note: This time is printed during real-time Joint debugging.
How to convert EXCEL Chinese characters to PinYin
We recommend that you copy a button to the WORD to convert it into pinyin. After the conversion, copy it to the EXCEL file.
How to convert Chinese characters into pinyin in excel
Hi.baidu.com/..d.html