iOS判断一段字符串长度(汉字2字节)
-(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;
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: [转]PHP7内核知识
- 下一篇: 贪心算法之物品分组
