当我解析来自 rss 的新闻描述时,有一个这种格式的链接:
2012 年 4 月 4 日的小发明(index.php?option=com_content task=view id=157 Itemid=100)。
我想展示一个带有链接文本的超链接:
2012 年 4 月 4 日的小发明
和链接地址:
index.php?option=com_content task=view id=157 Itemid=100
我该怎么做?
当我解析来自 rss 的新闻描述时,有一个这种格式的链接:
2012 年 4 月 4 日的小发明(index.php?option=com_content task=view id=157 Itemid=100)。
我想展示一个带有链接文本的超链接:
2012 年 4 月 4 日的小发明
和链接地址:
index.php?option=com_content task=view id=157 Itemid=100
我该怎么做?
您可以像这样获取所需的字符串:
NSString *string = [NSString stringWithString:@"Little invention of the 4 april 2012 (index.php?option=com_content task=view id=157 Itemid=100)"];
int linkStartIndex = [string rangeOfString:@"(" options:NSBackwardsSearch].location;
NSString *name = [string substringToIndex:linkStartIndex];
NSString *adress = [string substringWithRange:NSMakeRange(linkStartIndex+1, string.length-linkStartIndex-2)];
NSLog(@"\nname = [%@], \naddress = [%@]", name, adress);
如果您使用 UIWebView 来呈现它,请将此字符串添加到您的 webView 的 html 中:
NSString *linkTag = [NSString stringWithFormat:@"<a href=\"%@\">%@</a>", adress, name];