Skip to content

Instantly share code, notes, and snippets.

@akrabat
Created January 28, 2013 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akrabat/4657932 to your computer and use it in GitHub Desktop.
Save akrabat/4657932 to your computer and use it in GitHub Desktop.
Simple (No doubt, inefficient) word count system in Objective-C
-(NSUInteger) wordCount: (NSString *) string {
__block NSUInteger wordCount = 0;
[string enumerateSubstringsInRange:NSMakeRange(0, string.length)
options:NSStringEnumerationByWords
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
wordCount++;
}];
return wordCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment