我有一个URL
http://www.hdwallpapers.in/walls/honda_v4_concept_widescreen_bike-wide.jpg
我想提取文件名"honda_v4_concept_widescreen_bike-wide.jpg"
我怎么能这样做?
Apo*_*ARE 50
下面的代码应该有效.更新了它,所以我删除了顶部声明.我可以使用NSString vs const char*或来自C++的std :: string,但我认为C Character Pointers非常适合这种情况.
还改进了它,因此它有自己的简洁功能:
-(NSString*) extractFile:(const char*) url
{
NSURL *yourURL = [NSURL URLWithString:
[NSString stringWithCString:url
encoding:NSUTF8StringEncoding]];
return [yourURL lastPathComponent];
}
Run Code Online (Sandbox Code Playgroud)
使用:
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_]);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14533 次 |
最近记录: |