Last active
December 28, 2015 21:09
-
-
Save NikolaKirev/7562202 to your computer and use it in GitHub Desktop.
Find hashtag words in an NSString using NSPredicate
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
//A code snippet, that can be used to search for hashtags in a given NSString | |
//Instantiate a mutable array containing all the words. We sepparate the original string into words. | |
NSMutableArray *hashtagWordsArray = [NSMutableArray arrayWithArray:[<An NSString> componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]]; | |
NSPredicate *hashtagDetectionPredicate = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH %@", @"#"]; | |
[hashtagWordsArray filterUsingPredicate:hashtagDetectionPredicate]; | |
//Log the result | |
NSLog(@"Hashtags: %@", hashtagWordsArray); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment