通过string删除所有重音
surnameField.text = "Fal à èà ò l'opo"; // remove space and apostrophe NSString *surnarmeInput = [[surnameField.text stringByReplacingOccurrencesOfString:@" " withString:@""] stringByReplacingOccurrencesOfString:@"'" withString:@""];
我会删除也口音。
结果“Falaeaolopo”
// convert to a data object, using a lossy conversion to ASCII NSData *asciiEncoded = [yourOriginalString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; // take the data object and recreate a string using the lossy conversion NSString *other = [[NSString alloc] initWithData:asciiEncoded encoding:NSASCIIStringEncoding]; // relinquish ownership [other autorelease];
这将删除所有的口音..要删除所有的空间
NSString *yourFinalString = [other stringByReplacingOccurrencesOfString:@" " withString:@""];
第一部分删除重音,从这个线程复制dreamlax的答案代码
使用dataUsingEncoding:allowLossyConversion:似乎不适用于某些字符 – 例如Đ和đ。 我使用了特定的检查,然后是ascii编码。
尝试NSString中的dataUsingEncoding:allowLossyConversion:
方法。
- 如何将自定义button添加到UIActivityViewController?
- 在UIScrollView中向标准Pan Gesture Recognizer添加function
- 自定义视图看起来像UIAlertView
- pod安装失败,错误:在Pod中安装iOS时,由“Podfile”需要库(来自`../`)`
- 你可以编程访问Cocoa Touch中的标准本地化string吗?
- Swift中的泛型…
- 如何在UITabBarController中显示ViewController?
- 在数据库中build模重复事件,并使用UILocalNotification来触发事件
- Swift必须调用超类uiinputviewcontroller的指定初始值设定项