我想要完成的工作如下。我有一个UItextview
,其中一个句子在感知中有一个网址。我需要能够允许在URL
中添加UItextview
唯一URL
,同时从任何句子中显示的单个字符中获取总NSString
这是NSString
之内,例如:
假设我在UItextView
上有NSString *samplestr = @"This is a sample of a http://google.com/efg.php?EFAei687e3EsA sentence with a URL within it.";
:
{{1}}
答案 0 :(得分:3)
我认为您已查看以下代码
NSString *string = @"your string with url ";
NSDataDetector *linkDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [linkDetector matchesInString:string options:0 range:NSMakeRange(0, [string length])];
for (NSTextCheckingResult *match in matches) {
if ([match resultType] == NSTextCheckingTypeLink) {
NSURL *url = [match URL];
NSLog(@"found URL: %@", url);
}
}