Find URL from NSString

If you want to fetch a URL from a String:



NSString *StringContainingURL = @"You can click http://objectivecwithsuraj.blogspot.in/";
NSDataDetector *Detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [Detector matchesInString: StringContainingURL  options:0 range:NSMakeRange(0, [StringContainingURL  length])];
        for (NSTextCheckingResult *match in matches)
        {
            if ([match resultType] == NSTextCheckingTypeLink)
            {
                NSURL *url = [match URL];
                NSLog(@"URL : %@",url); 
            }
        }
   

Output of the log is:

Comments

Popular posts from this blog

UITableView - Add or Remove Rows Dynamically (Objective C & Swift Source codes)

payUmoney Payment Gateway Integration in iOS App (Objective C)

Check Internet Connectivity Using AFNetworking 2.0