[iOS] 统计文本长度

来源:互联网 发布:斯坦福大学 知乎 编辑:程序博客网 时间:2024/05/20 20:01
-(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;}


0 0
原创粉丝点击