从 NSURL 检索文件名 [英] Retrieve filename from NSURL
本文介绍了从 NSURL 检索文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网址
http://www.hdwallpapers.in/walls/honda_v4_concept_widescreen_bike-wide.jpg
我想提取文件名honda_v4_concept_widescreen_bike-wide.jpg"
I want to extract the file name which is "honda_v4_concept_widescreen_bike-wide.jpg"
我该怎么做?
推荐答案
下面的代码应该可以工作.更新了它,所以我删除了顶部语句.我本可以使用 C++ 中的 NSString 与 const char * 或 std::string ,但认为 C 字符指针非常适合这种情况.
The code below should work. Updated it so I removed the top statement. I could've used NSString vs const char * or std::string from C++ but thought C Character Pointers would be quite appropriate for this case in point.
还修改了它,使其具有自己的简洁功能:
Also revamped this so it's in it's own concise function:
-(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 检索文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文