检测NSString是否包含中文字符 [英] Detecting if NSString contains chinese characters

查看:99
本文介绍了检测NSString是否包含中文字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UISearchBar ,如果用户输入英文,我希望我的数据按pinYin排序,当用户输入中文字符时,我希望按字符本身排序。

I have an UISearchBar, and I want my data to be sorted by pinYin if the user inputs English, and sorted by the characters themselves when the user inputs Chinese characters.

是否有类似

if (searchText isKindofClass: UTF-8String) 

检测 NSString 是否包含中文字符?

to detect if an NSString contains Chinese characters?

推荐答案

您可以使用 NSRegularExpression 搜索字符系列:

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

他们给出了一个 \p {script = cyrillic} 的例子,我想通过搜索一下你会找到与中文有关的东西。

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

这篇关于检测NSString是否包含中文字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆