iOS 从url中获取文件名以及后缀

Posted Fleeming

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS 从url中获取文件名以及后缀相关的知识,希望对你有一定的参考价值。

//这里有一个模拟器沙盒路径(完整路径)

NSString* [email protected]"/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50.zip";

 

对路径截取的9种操作

    NSLog(@"1=%@",[index lastPathComponent]);

    NSLog(@"2=%@",[index stringByDeletingLastPathComponent]);

    NSLog(@"3=%@",[index pathExtension]);

    NSLog(@"4=%@",[index stringByDeletingPathExtension]);

    NSLog(@"5=%@",[index stringByAbbreviatingWithTildeInPath]);

    NSLog(@"6=%@",[index stringByExpandingTildeInPath]);

    NSLog(@"7=%@",[index stringByStandardizingPath]);

    NSLog(@"8=%@",[index stringByResolvingSymlinksInPath]);

    NSLog(@"9=%@",[[index lastPathComponent] stringByDeletingPathExtension]);

 

 

对应结果

 1=2013_50.zip

 2=/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books

3=zip

 4=/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50

5=~/Documents/DownLoad/books/2013_50.zip

 6=/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50.zip

 7=/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50.zip

8=/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50.zip

9=2013_50

 [转载]



以上是关于iOS 从url中获取文件名以及后缀的主要内容,如果未能解决你的问题,请参考以下文章

python通过url获取文件名和文件的后缀

获取文件名以及后缀

java 通过文件后缀名/ URL /文件路径/ MIME获取并判断该文件是什么类型(视频/图像...)

获取文件名以及后缀名

从 URL 下载/获取文件的 SBT 任务

java 删除文件后缀名