試圖從文本刪除URL重寫:的NSString不使用新值
- (NSString *)cleanText:(NSString *)text{
NSString *string = @"This is a sample of a http://abc.com/efg.php?EFAei687e3EsA sentence with a URL within it.";
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) {
NSString *matchingString = [match description];
NSLog(@"found URL: %@", matchingString);
string = [string stringByReplacingOccurrencesOfString:matchingString withString:@""];
}
}
NSLog(string);
return string;
}
然而string
收益不變(沒有匹配)。
UPD:控制檯輸出:
found URL: <NSLinkCheckingResult: 0xb2b03f0>{22, 36}{http://abc.com/efg.php?EFAei687e3EsA}
2013-10-02 20:19:52.772
This is a sample of a http://abc.com/efg.php?EFAei687e3EsA sentence with a URL within it and a number 097843.
準備工作食譜由@Raphael Schweikert完成。
只是試圖it.works我。我知道你相信有一場比賽,但你可以發佈matchingString的日誌嗎? –
@abhineetprasad感謝您的信息。我會用輸出更新帖子。 – Shmidt