Using CFStringTransform to convert Chinese characters into Pinyin is time consuming !, Cfstringtransform

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.