1) . As mentioned in the comments, your string consists of 5 composed sequences of characters (or clusters of characters, if you prefer). When you break into unichar as the NSString s length method, you get 7, which is the unichar number that is required to represent your string in memory.
2) . Apparently, UITextField and UITextView process strings in unichar mode. Good news, so are you. See No. 3.
3) . You can get the number of arranged character sequences using some NSString API that handles folded character sequences correctly. The quick example that I baked, really fast, is a small NSString category:
@implementation NSString (ComposedCharacterSequences_helper) -(NSUInteger)numberOfComposedCharacterSequences{ __block NSUInteger count = 0; [self enumerateSubstringsInRange:NSMakeRange(0, self.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop){ NSLog(@"%@",substring);
Again, this is a quick code; but he must start you. And if you use it like this:
NSString *string = @"(# οΎοΎ)"; NSLog(@"string length %i", string.length); NSLog(@"composed character count %i", [string numberOfComposedCharacterSequences]);
You will see that you get the desired result.
For a detailed explanation of the NSString API, check out the WWDC 2012 Session 215 Video "Text and Linguistic Analysis"
source share