标签:
HanyuPinyinOutputFormat *fmt = [[HanyuPinyinOutputFormat alloc]init];
fmt.caseType = CaseTypeUppercase; // 表示按大写字母输出
fmt.toneType = ToneTypeWithoutTone; // 表示不带声调
fmt.vCharType = VCharTypeWithUUnicode; // v以ü表示
NSString *pinyin = [PinyinHelper toHanyuPinyinStringWithNSString:@"北京" withHanyuPinyinOutputFormat:fmt withNSString:@"#"];
参数1:@"北京", 待转换的中文字符串
参数2:fmt, 输出格式
参数3:@"#", 分隔符,可以是空字符串 @""
打印字符串pinyin的结果: BEI#JING
NSString *pinyin2 = [PinyinHelper toHanyuPinyinStringWithNSString:city.name withHanyuPinyinOutputFormat:fmt withNSString:@"#"];
NSArray *words = [pinyin2 componentsSeparatedByString:@"#"];
NSMutableString *headLetterStr = [NSMutableString string];
[words enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[headLetterStr appendString:[(NSString *)obj substringToIndex:1]];
}];
if( ([city.name rangeOfString:condition].length != 0) ||
([pinyin rangeOfString:condition.uppercaseString].length != 0) ||
([headLetterStr rangeOfString:condition.uppercaseString].length != 0)
)
{
// 搜索成功,需要做的事情
}
标签:
原文地址:http://www.cnblogs.com/oumygade/p/4225376.html