2011-08-21 1 views
1

NSURLがNSTextCheckingResultに返されることを理解していますが、元の文字列に戻すにはどうすればよいですか。 NSURLは、元のURLに戻る方法がない限り、URLをフォーマットします。NSTextCheckingResultから元の文字列に戻すにはどうすればよいですか?

NSError *error = nil; 
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes: 
           (NSTextCheckingTypeLink | NSTextCheckingTypePhoneNumber) 
                   error:&error]; 


    [detector enumerateMatchesInString:html 
     options:0 
     range:NSMakeRange(0, [html length]) 
     usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) { 

      if (result.resultType == NSTextCheckingTypeLink) { 
       NSLog(@"original string is %@", ???); 
      } 

     } 
    }]; 

答えて

2

試してみてください。

 if (result.resultType == NSTextCheckingTypeLink) 
     { 
      NSLog(@"original string is %@", 
       [result.URL isFileURL] ? [result.URL path] : [result.URL absoluteString]); 
     } 

それとも、URLについて知りたいものは何でも得ます。

関連する問題