gpt4 book ai didi

nsurl - 从NSURL检索文件名

转载 作者:行者123 更新时间:2023-12-03 09:19:29 26 4
gpt4 key购买 nike

我有一个网址

http://www.hdwallpapers.in/walls/honda_v4_concept_widescreen_bike-wide.jpg

我要提取的文件名为“honda_v4_concept_widescreen_bike-wide.jpg”

我该怎么做?

最佳答案

下面的代码应该工作。更新了它,所以我删除了最上面的语句。我本来可以使用C++中的NSString vs const char *或std::string,但我认为C字符指针非常适合这种情况。

还对其进行了修改,使其具有自己的简洁功能:

-(NSString*) extractFile:(const char*) url 
{
NSURL *yourURL = [NSURL URLWithString:
[NSString stringWithCString:url
encoding:NSUTF8StringEncoding]];
return [yourURL lastPathComponent];
}

使用:
const char *path_ = "http://www.hdwallpapers.in/walls/honda_v4_concept_widescreen_bike-wide.jpg";
NSLog(@"\t\tYour Extracted file: \n\t%@", [self extractFile:path_]);

关于nsurl - 从NSURL检索文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19964198/

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