01 | -(NSUInteger) unicodeLengthOfString: (NSString *) text { |
02 | NSUInteger asciiLength = 0; |
03 | for (NSUInteger i = 0; i < text.length; i++) { |
04 | unichar uc = [text characterAtIndex: i]; |
05 | asciiLength += isascii(uc) ? 1 : 2; |
06 | } |
07 | NSUInteger unicodeLength = asciiLength / 2; |
08 | if(asciiLength % 2) { |
09 | unicodeLength++; |
10 | } |
11 | return unicodeLength; |
12 | } |
没有评论:
发表评论