我正在编写一个 iOS 应用程序,它从不受我控制的服务器下载一些数据。我没有使用自定义数据检测器。返回的 JSON 中的字符串仍然包含它们的 HTML url 标签,我想删除它们,因为我想在 UITextView 中显示字符串,而这些类型的字符串
<strong><a href="http://instagram.com/emotionslive" rel="nofollow">Instagram</a></strong> / <strong><a href="http://www.behance.net/creativemints" rel="nofollow">Behance</a></strong>
<a href="http://readdle.com/" rel="nofollow"><strong>Live Now</strong></a>
我真正想要的是这个:
解决这个问题的最佳方法是什么?
- 我应该使用正则表达式从文本中去除 url 标签吗?
- 这样做时,我会丢失“描述”链接(在上面的示例中为“Instagram”和“Behance”)吗?
- 使用 UIWebView 会更容易吗?
如果这太难/不可能,那么只包含 URL,而不包含其描述也可以。
谢谢!
最佳答案
Should I strip the url tags from the text using regex?
没有。 HTML 过于复杂,无法使用 RegEx 正确解析。您将需要一个 XML 解析器。
Would I lose the link "descriptions" (in the above example, "Instagram" and "Behance") when I do that?
您不必使用 XML 解析器。您可能会使用 RegEx,尤其是当您无法准确控制返回的内容时。
Would this be way easier using a UIWebView?
是的。这就是我会做的,除非你有充分的理由不这样做。
关于ios - 删除 iOS 中的 HTML url 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20293446/