iOS判断一段字符串长度(汉字2字节)

来源:互联网 发布:java项目视频教程 编辑:程序博客网 时间:2024/05/18 00:36
-(NSUInteger)textLength: (NSString *) text{    NSUInteger asciiLength = 0;    for (NSUInteger i = 0; i < text.length; i++) {        unichar uc = [text characterAtIndex: i];        asciiLength += isascii(uc) ? 1 : 2;    }    NSUInteger unicodeLength = asciiLength;    return unicodeLength;}
原创粉丝点击