美文网首页iOS
iOS__ 怎么判断字符串是汉字还是字母

iOS__ 怎么判断字符串是汉字还是字母

作者: CoderJohnhao | 来源:发表于2017-01-11 17:30 被阅读222次
if(self.textLabel){
        for (int i=0; i<self.textLabel.length; i++) {
            NSRange range=NSMakeRange(i,1);
            NSString *subString=[self.textLabel substringWithRange:range];
            const char *cString=[subString UTF8String];
            if (strlen(cString) == 3)
            {
                NSLog(@"是汉字");
            }else if(strlen(cString) == 1)
            {
                NSLog(@"是字母");
            }
        }
    }

相关文章

网友评论

    本文标题:iOS__ 怎么判断字符串是汉字还是字母

    本文链接:https://www.haomeiwen.com/subject/ururbttx.html