如何在 iPhone 中查找和获取 NSString 中的 URL?
我在 NSString 中有一个带有 http:// 的文本。我想从 NSString 获取 http 链接。如何从字符串中获取链接/url?例如:“Stack over flow 对于初学者来说是非常有用的链接https://stackoverflow.com/”。我想从文本中获取“https://stackoverflow.com/”。我该怎么做?提前致谢。
I have a text with http:// in NSString. I want to get that http link from the NSString. How can i get the link/url from the string? Eg: 'Stack over flow is very useful link for the beginners https://stackoverflow.com/'. I want to get the 'https://stackoverflow.com/' from the text. How can i do this? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定链接的确切含义,但如果您想将 NSString 转换为 NSURL,则可以执行以下操作:
编辑
这是获取给定 NSString 中的所有 URL 的方法:
I am not sure what you exactly mean by link but if you want to convert your NSString to NSURL than you can do the following:
EDIT
This is how to get all URLs in a given NSString:
您可以只搜索以 @"http://" 开头的子字符串,而不是将字符串拆分为数组并以这种方式搞乱:
Rather than splitting the string into an array and messing about that way, you can just search for the substring beginning with @"http://":
试试这个:
这将在 nsarray 中给出两个对象。第一个对象将具有:
Stack over flow对于初学者来说非常有用的链接
,第二个对象将是:://stackoverflow.com/
(我猜)那么你可以这样做喜欢:
然后喜欢:
相当长,但我认为这对你有用。希望对您有帮助。
try this :
this will give two objects in the nsarray. 1st object will be having:
Stack over flow is very useful link for the beginners
and 2nd will be :://stackoverflow.com/
(i guess)then you can do like:
then do like:
Quite a lengthy,but i think that would work for you. Hope that helps you.