0

Is it possible to recognize an url in xCode ? I'm trying to create an if statement, followed by opening the url.

I can't find anything about this on the internet, I've also tried searching for recognizing the first letters (like "http, file, www");

With kind regards, Tim

Tim Lodder
  • 49
  • 1
  • 12

2 Answers2

0

Use a regular expression to check for the patterns you want (www, http, https, etc)

http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSRegularExpression_Class/Reference/Reference.html

And here is a great regex http://www.geekzilla.co.uk/view2D3B0109-C1B2-4B4E-BFFD-E8088CBC85FD.htm

And here is an example from stackoverflow, How to validate an url on the iPhone

Community
  • 1
  • 1
Eric
  • 172
  • 11
0

NSString class has a method rangeOfStrig:

NSString *urlString = @"http://www.someurl.com";
if ([urlString rangeOfString:@"www"].location != NSNotFound ) {
    // do something
}
beryllium
  • 29,669
  • 15
  • 106
  • 125