您的位置:首页 > 移动开发 > IOS开发

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

2017-05-27 18:17 357 查看
-(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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐