Number of characters in an NSString
You can enumerate the characters in the string with theNSStringEnumerationByComposedCharacterSequences
option:
NSString *string = @"0̄ 😄";__block NSUInteger count = 0;[string enumerateSubstringsInRange:NSMakeRange(0, [string length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { count++; }];NSLog(@"%ld %ld", (long)count, (long)[string length]);// Output: 3 5
Both the decomposed character 0̄ and the Emoji 😄 (which is also stored as two UTF-16 characters – a so-called "surrogate pair") are counted as one.