gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 03:34:23 25 4
gpt4 key购买 nike

假设我有字符串:

"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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com