How to check if a char lies between a certain unicode range…?

痞子三分冷 提交于 2019-12-23 23:54:36

问题


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:


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).



来源:https://stackoverflow.com/questions/9972055/how-to-check-if-a-char-lies-between-a-certain-unicode-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!