iphone - 如何检查一个字符是否位于某个 unicode 范围之间...?

标签 iphone ios unicode utf-8 character-encoding

我想检查从文本字段获得的特定字符是否位于unicode字符集的特定十六进制范围之间...就像如果我输入大写C那么我将指定范围41-5a..我想对俄语字母表执行此操作。但无法弄清楚。我可以使用输入的最后一个字符..

unichar lastEnteredChar= [[textField.text stringByReplacingCharactersInRange:range withString:string] characterAtIndex:[[textField.text stringByReplacingCharactersInRange:range withString:string]  length] - 1];

但不知道该去哪里。

最佳答案

您可以像这样访问 UITextField 中的特定字符:

unichar charAt0 = [myTextField.text characterAtIndex:0];

所以如果你想要最后一个字符:

NSUInteger length = [myTextField.text length];
unichar lastChar = [myTextField.text characterAtIndex:length - 1];

现在 lastChar 实际上只是一个 无符号短,因此您可以像这样比较它:

if( lastChar >= 0x041 && lastChar <= 0x05A )
{
    // do something...
}

是否要将其限制在十六进制范围或其他范围,取决于您。我选择了您提供的示例(41 到 5a)。

关于iphone - 如何检查一个字符是否位于某个 unicode 范围之间...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9972055/

相关文章:

ios - 如何在 iOS 上拍摄全屏相机照片?

ios - 如何模拟后台附件 iPad

iOS 在容器内移动 View 会混淆触摸区域

Oracle 无法将数据插入 varchar2(4000 char) 列

iphone - 从数组填充表格仅显示在第一个单元格上

ios - 一部 Iphone 6 与另一部的布局差异

iphone - 在 iOS 上创建用作数据库的简单文件,用于搜索邮政编码

java - @property 后的多个类类型变量上的 "Interface type cannot be statically allocated"

gwt - 将 éàçè... 替换为 GWT 中的等效 "eace"

python - 使用 BeautifulSoup 在 python 中进行编码