iphone - Objective-C - 在字符串中查找 URL

标签 iphone objective-c nsstring

给定一个大字符串,创建包含字符串中所有有效 url 的数组的最佳方法是什么?

最佳答案

不需要为此使用 RegexKitLite,因为 iOS 4 Apple 提供了 NSDataDetector(NSRegularExpression 的子类)。

你可以像这样简单地使用它(source 是你的字符串):

NSDataDetector* detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray* matches = [detector matchesInString:source options:0 range:NSMakeRange(0, [source length])];

关于iphone - Objective-C - 在字符串中查找 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5998969/

相关文章:

iphone - 将 .zip 文件转换为 NSData

javascript - 如何在 iphone/ipad 或其他移动设备上禁用某个 javascript?

objective-c - 当单元格包含 UITextView 时,不会触发 UITableView willDisplayCell

objective-c - NSString 字符的位置

ios - 将数据从 Google Places API 发送到 TableView

objective-c - componentsSeparatedByString内存泄漏,能帮我吗?

ios - 将一个 NSString 复制到另一个 Xcode

iphone - 以最快的方式获取 facebook 好友头像 - iOS

iphone - 我想要 iLBC 格式,但似乎只能录制 IMA4 格式的音频

iphone - 自动布局无法按预期工作