+(NSString*)transformToPinyin:(NSString*)aString
{
//转成了可变字符串
NSMutableString *str = [NSMutableString stringWithString:aString];
CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformMandarinLatin,NO);
//再转换为不带声调的拼音
CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformStripDiacritics,NO);
NSArray*pinyinArray = [strcomponentsSeparatedByString:@" "];
NSMutableString *allString = [NSMutableString new];
intcount =0;
for(int i =0; i < pinyinArray.count; i++)
{
for(inti =0; i < pinyinArray.count;i++)
{
if(i == count) {
[allStringappendString:@"#"];
//区分第几个字母
}
[allStringappendFormat:@"%@",pinyinArray[i]];
}
[allStringappendString:@","];
count ++;
}
NSMutableString *initialStr = [NSMutableString new];
//拼音首字母
for(NSString*sinpinyinArray)
{
if(s.length>0)
{
[initialStrappendString: [ssubstringToIndex:1]];
}
}
[allStringappendFormat:@"#%@",initialStr];
[allStringappendFormat:@",#%@",aString];
returnallString;
}
网友评论