Objective-C - 在字符串中查找URL [英] Objective-C - Finding a URL within a string
本文介绍了Objective-C - 在字符串中查找URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个大字符串,创建一个包含在字符串中的所有有效URL的数组的最佳方法是什么?
Given a large string, what is the best way to create an array of all valid urls which are contained within the string?
推荐答案
不需要使用 RegexKitLite
,因为iOS 4 Apple提供 NSDataDetector
(<$ c的子类$ c> NSRegularExpression )。
No need to use RegexKitLite
for this, since iOS 4 Apple provide NSDataDetector
(a subclass of NSRegularExpression
).
您可以像这样使用它( source
是你的字符串):
You can use it simply like this (source
is your string) :
NSDataDetector* detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray* matches = [detector matchesInString:source options:0 range:NSMakeRange(0, [source length])];
这篇关于Objective-C - 在字符串中查找URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文