Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何从HTML字符串中获取HREF链接url_Ios_Ios4_Ios5 - Fatal编程技术网

Ios 如何从HTML字符串中获取HREF链接url

Ios 如何从HTML字符串中获取HREF链接url,ios,ios4,ios5,Ios,Ios4,Ios5,在我的iOS应用程序中,我想从这个html字符串中获取url地址,并将其显示在UILabel上。我该怎么做 <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&l

在我的iOS应用程序中,我想从这个html字符串中获取url地址,并将其显示在UILabel上。我该怎么做

<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>

如何从HTML字符串中提取HREF值

在这里,我想得到值'http://www.youtube.com/watch?v=689mBder ' ..

试试这个

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);

你是想在CSS中(在一个web框架中?)提取这个,还是想在Objective C中(在一个程序中)提取这个?你的背景不清楚。请编辑您的原始问题,说明您正在尝试做什么以及目的。从您的评论中,我猜您将尝试使用正则表达式,我可以告诉您:不要!查看锚()引用href之前的目标后,哪个将完全失败。