我想检查从文本字段获得的特定字符是否位于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/