【问题标题】:How to check if a char lies between a certain unicode range...?如何检查一个字符是否位于某个 unicode 范围之间......?
【发布时间】:2012-04-02 06:57:36
【问题描述】:

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

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

但不知道从这里去哪里。

【问题讨论】:

    标签: iphone ios unicode utf-8 character-encoding


    【解决方案1】:

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

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

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

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

    现在lastChar 真的只是一个unsigned short,所以你可以这样比较:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-21
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多