我使用此函数从字符串中获取 URL,但如何取回它?

- (NSString *)urlEncodeUsingEncoding:(NSStringEncoding)encoding forString:(NSString *)string {
    string = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)string, NULL, (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ", CFStringConvertNSStringEncodingToEncoding(encoding));
    return string;
}

最佳答案

[string stringByReplacingPercentEscapesUsingEncoding:NSUTF8Encoding];

顺便提一句。如果将NSURL用作文件url,请确保使用[url path]来获取未转义的路径字符串,而不是[url absoluteString]

10-05 17:44