Advertisement
Guest User

Untitled

a guest
May 22nd, 2013
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. NSError* error = nil;
  2.  
  3. NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"(?:\\s|\\A)[##]+([A-Za-z0-9-_]+)" options:0 error:&error];
  4. NSArray* matches = [regex matchesInString:tweetText options:0 range:NSMakeRange(0, [tweetText length])];
  5. NSString* processedString = [[tweetText copy] autorelease];
  6. for ( NSTextCheckingResult* match in matches )
  7. {
  8. NSString* matchText = [tweetText substringWithRange:[match range]];
  9. NSString *matchText2 = [matchText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  10. NSString *search = [matchText2 stringByReplacingOccurrencesOfString:@"#"
  11. withString:@""];
  12. NSString *searchHTML= [NSString stringWithFormat:@"<a href='https://twitter.com/search?q=%%23%@'>%@</a>",search,matchText];
  13. processedString = [processedString stringByReplacingOccurrencesOfString:matchText
  14. withString:searchHTML];
  15. NSLog(@"match: %@", processedString);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement