How to check if a char lies between a certain unic

2019-07-17 03:19发布

I want to check if a particular char I get from the text field lies between a particular hex range of unicode character set... Like if I enter capital C then I will specify the range 41-5a.. I want to do this for russian alphabet. But cant figure it out.I can get the last char entered using..

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

but don't know where to go from here.

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-07-17 04:01

You can access a particular character in the UITextField like so:

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

So if you want the last character:

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

Now lastChar is really just an unsigned short, so you can compare it like so:

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

Whether you want to constrain it to a hex range, or some other range, is up to you. I chose the examples you gave (41 thru 5a).

查看更多
登录 后发表回答