iphone - Objective-C:如何检测字符串中的 http URL?

标签 iphone objective-c regex cocoa-touch nsstring

假设我有字符串:

"I love visiting http://www.google.com"

如何检测 token ,http://www.google.com

最佳答案

您可以使用 NSDataDetectors这些是在 iOS4 中添加的,非常有用。您想要使用 NSTextCheckingTypeLink 创建一个数据检测器并让它执行它的操作。

NSString *testString = @"Hello http://google.com world";
NSDataDetector *detect = [[NSDataDetector alloc] initWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [detect matchesInString:testString options:0 range:NSMakeRange(0, [testString length])];
NSLog(@"%@", matches);

关于iphone - Objective-C:如何检测字符串中的 http URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7014119/

相关文章:

iphone - 应用内购买 (IAP) 简单问题(我有问题)

python - 运动正则表达式 G 代码 +Python

ios - ResignFirstResponder 崩溃

ios - Objective-C - UIButton 保持高亮/选中状态,背景颜色和字体颜色在高亮/选中时发生变化

iphone - 如何管理多个异步 NSURLConnection 委托(delegate)?

ios - Eddystone 信标检测问题

javascript - 获取四个括号内的字符串(正则表达式)

java - 请证明 Regex Java 程序中的输出

iphone - NSDictionary 添加 NULL 键值

objective-c - 如何在 objective-c 中给出 toast 信息