gpt4 book ai didi

objective-c - UrlByAppendingPathComponent 与 UrlByAppendingPathExtension

转载 作者:技术小花猫 更新时间:2023-10-29 10:59:33 29 4
gpt4 key购买 nike

我已阅读文档,看起来某些边缘情况可能有所不同(尾部斜杠等),但我不清楚这两种方法之间的主要区别是什么。 Component 和 Extension 这两个术语在 URL 世界中是否有除我以外的人理解的特殊含义?

最佳答案

路径扩展用于在URL 中添加.html 等内容,路径组件用于添加/news/local 等内容。路径扩展的文档:

If the original URL ends with one or more forward slashes, these are removed from the returned URL. A period is inserted between the two parts of the new URL.

所以 http://hello.com/news/ 会变成 http://hello.com/news.html

路径组件的文档:

If the original URL does not end with a forward slash and pathComponent does not begin with a forward slash, a forward slash is inserted between the two parts of the returned URL, unless the original URL is the empty string.

所以 http://hello.com/news/ 会变成 http://hello.com/news/html

这是一个快速测试:

NSURL *originalURL = [NSURL URLWithString:@"http://hello.com/news"];
NSLog(@"%@", [originalURL URLByAppendingPathComponent:@"local"]);
NSLog(@"%@", [originalURL URLByAppendingPathExtension:@"local"]);

输出:

http://hello.com/news/local
http://hello.com/news.local

关于objective-c - UrlByAppendingPathComponent 与 UrlByAppendingPathExtension,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10404550/

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