Reputation: 12405
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.
Upvotes: 2
Views: 725
Reputation: 4176
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).
Upvotes: 3