Created
July 24, 2017 09:34
-
-
Save juwencheng/907d25375ffe9ae68d606958f6f25529 to your computer and use it in GitHub Desktop.
得到NSString可视字符串的长度,比如包含1个emoji表情的字符串,长度应该是1,而不是2。Unicode 的code point 到 UTF-16转换产生的问题。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *s = @"😀"; | |
__block NSInteger count = 0; | |
[s enumerateSubstringsInRange:NSMakeRange(0, s.length) options:NSStringEnumerationBySentences usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) { | |
count++; | |
}]; | |
NSLog(@"%d", count); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment