Skip to content

Instantly share code, notes, and snippets.

@agassiyzh
Created July 28, 2016 09:14
Show Gist options
  • Save agassiyzh/7b6ec49375dfcbf5a377893e39ca0150 to your computer and use it in GitHub Desktop.
Save agassiyzh/7b6ec49375dfcbf5a377893e39ca0150 to your computer and use it in GitHub Desktop.
@interface NSString (TDF)
- (NSUInteger)tdf_chineseLength;
@end
@implementation NSString(TDF)
- (NSUInteger)tdf_chineseLength {
NSInteger length = [self lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
length -= (length - self.length) / 2;
length = (length +1) / 2;
return length;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment