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

IOS类似新浪微博统计汉字/英文/标点符号等字符长度

2014-02-24 17:53 316 查看
-(NSUInteger) unicodeLengthOfString: (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 / 2;



if(asciiLength % 2) {

unicodeLength++;

}

return unicodeLength;

}

即:ASCII和Unicode混合文本长度

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