0

in my iOS application i want to take the url adress from this html string and display it on a UILabel. How can i do this

<a href="http://www.youtube.com/watch?v=689mBder" target="_blank" rel="nofollow nofollow" onmousedown="UntrustedLink.bootstrap($(this), "vAQELu2Ne", event, bagof({}));">click here to watch</a>

How can I extract the HREF value from an HTML string.

Here i want to get the value 'http://www.youtube.com/watch?v=689mBder ' ..

  • Are you trying to extract this in CSS (within a web frame?) or are you trying to do this in Objective C (within a program)? Your context is not clear. Please edit your original question to say more of what you are trying to do and for what purpose. – Michael Dautermann Nov 27 '11 at 14:31
  • From your comment, I guess you will be trying to use regular expressions and I can tell you this: DONT! See http://stackoverflow.com/questions/677038/how-to-use-regular-expressions-to-parse-html-in-java – Till Nov 27 '11 at 17:54

1 Answers1

1

Try this

NSRange start = [string rangeOfString:@"http://www.youtube.com/"];
NSRange end = [string rangeOfString:@"\" "];

int rangeLength = (int)(end.location - start.location);

NSString *hrefString = [[NSString alloc] initWithString:[string substringWithRange:NSMakeRange(start.location, rangeLength)]];
NSLog(@"%@",hrefString);
syclonefx
  • 2,830
  • 1
  • 21
  • 24