Created
May 19, 2011 15:42
-
-
Save Adam0101/981063 to your computer and use it in GitHub Desktop.
sanitize search twitter
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
//Create the regular expression to match against whitespace or % or ^ | |
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(\\s|%|^)" options:NSRegularExpressionCaseInsensitive error:&error]; | |
//Create the regular expression to match against hash tags | |
NSRegularExpression *regexHash = [NSRegularExpression regularExpressionWithPattern:@"#" options:NSRegularExpressionCaseInsensitive error:&error]; | |
// create the new string by replacing the matching of the regex pattern with the template pattern(whitespace) | |
NSString *tempString = [regex stringByReplacingMatchesInString:searchTerm options:0 range:NSMakeRange(0, [searchTerm length]) withTemplate:@"%20"]; | |
// create the new string by replacing the matching of the regex pattern with the template pattern(whitespace) | |
NSString *hashTempString = [regexHash stringByReplacingMatchesInString:tempString options:0 range:NSMakeRange(0, [searchTerm length]) withTemplate:@"%23"]; | |
searchTerm = hashTempString; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment