Created
January 13, 2011 19:14
-
-
Save Adam0101/778415 to your computer and use it in GitHub Desktop.
Example of character substitution using NSRegularExpression
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 *)grabData:(NSString *)searchTerm { | |
// Setup an error to catch stuff in | |
NSError *error = NULL; | |
//Create the regular expression to match against | |
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\s" options:NSRegularExpressionCaseInsensitive error:&error]; | |
// create the new string by replacing the matching of the regex pattern with the template pattern(whitespace) | |
NSString *newSearchString = [regex stringByReplacingMatchesInString:searchTerm options:0 range:NSMakeRange(0, [searchTerm length]) withTemplate:@"%20"]; | |
NSLog(@"New string: %@",newSearchString); | |
return newSearchString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment