Last active
August 29, 2015 14:13
-
-
Save ylem/528c3deb2abcdbf14696 to your computer and use it in GitHub Desktop.
Calculate word count
This file contains 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 *string = @"中华人民共和国万岁 万岁 万万岁"; | |
NSCountedSet *countedSet = [NSCountedSet new]; | |
[string enumerateSubstringsInRange:NSMakeRange(0, [string length]) | |
options:NSStringEnumerationByComposedCharacterSequences | NSStringEnumerationLocalized | |
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop){ | |
_sumText++; | |
[countedSet addObject:substring]; | |
}]; | |
NSLog(@"%lu", _sumText); | |
NSLog(@"%@", countedSet); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment