Detecting if NSString contains chinese characters

烂漫一生 提交于 2019-11-29 15:45:56

You can use a NSRegularExpression to search for "character families" :

https://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSRegularExpression_Class/Reference/Reference.html

http://userguide.icu-project.org/strings/regexp

They give an example of \p{script=cyrillic}, I guess by searching a little you'll find something related to Chinese.

Eren

If you use \p{script=Han} to detecting Chinese, be sure to add '\' before \p. So it is like

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\\p{Script=Han}" options:NSRegularExpressionCaseInsensitive error:&error];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!