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
{
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
相关文章推荐
- 统计汉字/英文/标点符号混编时的字符个数
- 统计汉字长度2个英文字符=1个中文
- 统计文本文件的汉字和英文字符的个数
- iOS UITextField 限制输入长度,中英文混排,汉字占2个长度,英文数字占1个长度
- JavaScript 计算汉字和英文字符的长度
- 获取包含中文,字母,数字集合的字符串的长度(1个汉字字符存储需要2个字节,1个英文字符存储需要1个字节)
- JS判断字符串长度(英文占1个字符,中文汉字占2个字符)
- PHP统计包含汉字的字符长度 ( 改善Smarty modifier.truncate.php 中文支持)
- 微博中统计文本框里面的字数(两个英文字符占一个汉字位置)
- C#、Java实现按字节截取字符串包含中文汉字和英文字符数字标点符号等
- JS判断字符串长度(英文占1个字符,中文汉字占2个字符)
- 中与英文统计字符长度
- 统计文本文件的汉字和英文字符的个数
- JS判断字符串长度(英文占1个字符,中文汉字占2个字符)
- JS判断字符串长度(英文占1个字符,中文汉字占2个字符)
- JS判断字符串长度(英文占1个字符,中文汉字占2个字符)
- JS判断字符串长度(英文占1个字符,中文汉字占2个字符)
- iOS textfield限制长度,中文占2字符,英文占1字符
- JS获取字符串长度(英文占1个字符,中文汉字占2个字符)
- javascript 汉字占两个字符 统计长度的方法