作者:少钧13 | 来源:互联网 | 2024-10-19 18:45
按照中文两个字符,英文数字一个字符计算字符数-(NSUInteger)unicodeLengthOfString:(NSString*)text{NSUIntegera
//按照中文两个字符,英文数字一个字符计算字符数
-(NSUInteger)unicodeLengthOfString:(NSString *)text {
NSUInteger asciiLength =0;
for (NSUInteger i =0; i length; i++) {
unichar uc = [textcharacterAtIndex: i];
asciiLength +=isascii(uc) ? 1 :2;
}
NSLog(@"字符长度为: %@",@(asciiLength));
return asciiLength;
}