中英文字符计算

来源:互联网 发布:淘宝直播秒杀是真的吗 编辑:程序博客网 时间:2024/06/10 23:52

//按照中文两个字符,英文数字一个字符计算字符数

-(NSUInteger)unicodeLengthOfString:(NSString *)text {

    NSUInteger asciiLength =0;

    for (NSUInteger i =0; i < text.length; i++) {

        unichar uc = [textcharacterAtIndex: i];

        asciiLength +=isascii(uc) ? 1 :2;

    }

    

    NSLog(@"字符长度为: %@",@(asciiLength));

    return asciiLength;

}

0 0
原创粉丝点击