Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSError* error = nil;
- NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"(?:\\s|\\A)[##]+([A-Za-z0-9-_]+)" options:0 error:&error];
- NSArray* matches = [regex matchesInString:tweetText options:0 range:NSMakeRange(0, [tweetText length])];
- NSString* processedString = [[tweetText copy] autorelease];
- for ( NSTextCheckingResult* match in matches )
- {
- NSString* matchText = [tweetText substringWithRange:[match range]];
- NSString *matchText2 = [matchText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
- NSString *search = [matchText2 stringByReplacingOccurrencesOfString:@"#"
- withString:@""];
- NSString *searchHTML= [NSString stringWithFormat:@"<a href='https://twitter.com/search?q=%%23%@'>%@</a>",search,matchText];
- processedString = [processedString stringByReplacingOccurrencesOfString:matchText
- withString:searchHTML];
- NSLog(@"match: %@", processedString);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement