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

[转载]

时间: 2024-08-01 18:28:42

iOS 从url中获取文件名以及后缀的相关文章

js使用正则表达式从url中获取参数值

//从url中获取参数值 function getvl(name) { var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i"); if (reg.test(location.href)) return unescape(RegExp.$2.replace(/\+/g, " ")); return ""; };

如何从浏览器的url中获取参数信息

浏览器宿主环境中,有一个location对象,同时这个对象也是window对象和document对象的属性. location对象中提供了与当前窗口加载的文档有关的信息,即url信息. 如:https://www.baidu.com/api/sousu?search=baidu&id=123#2 location.href:完整的url location.protocol:返回协议(https) location.host:返回服务器名称和端口号(www.baidu.com) location.

Java中获取文件名、类名、方法名、行号的方法

??在C语言中,可以通过宏FILE.LINE来获取文件名和行号,在Java语言中,则可以通过StackTraceElement类来获取文件名.类名.方法名.行号,具体代码如下: public static int getLineNumber( ){ StackTraceElement[] stackTrace = new Throwable().getStackTrace(); return stackTrace[1].getLineNumber( ); } public static Stri

IOS从视频中获取截图

从视频中获取截图: NSString *movpath =[[NSBundle mainBundle] pathForResource:@”iosxcode4″ ofType:@”mov”]; mpviemController =[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:movpath]]; MPMoviePlayerController *mp=[mpviemController

获取文件名以及后缀

// 从路径中获得完整的文件名(带后缀) exestr = [filePath lastPathComponent]; NSLog(@"%@",exestr); // 获得文件名(不带后缀) exestr = [exestr stringByDeletingPathExtension]; NSLog(@"%@",exestr); // 获得文件的后缀名(不带'.') exestr = [filePath pathExtension]; NSLog(@"%@

【iOS】程序中获取应用的信息

iOS应用中,经常使用到一些程序自身的参数设定,故记录一笔. 1 //Build号 2 NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; 3 //Version号 4 NSString *shortVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundl

从一个带有http://网络文件中获取文件名

例如文件网址为: http://a.hiphotos.baidu.com/image/h%3D200/sign=c3da85e50123dd543e73a068e108b3df/80cb39dbb6fd5266d8dfc595a318972bd50736be.jpg 经过解析,获得文件名为:80cb39dbb6fd5266d8dfc595a318972bd50736be.jpg 实现过程,拿到网址的字符串,从后向前查找,当查找到  “/” 时,返回此时的index(即最后一个“/”的位置), 然

PHP 中获取文件名及路径

1. basename("/mnt/img/image01.jpg")函数:得到文件名;输出结果为:image01.jpg.    使用 basename($uriString) 我们可以得到一个包含扩展名的文件名: 如果不需要扩展名,也可以使用 basename($uriString, $extString) 过滤扩展名,仅仅返回文件名. 2. echo __FILE__;得到当前请求文件的完整路径,输出格式如:/mnt/hgfs/ictsapce/test/index.php 3.

从文件路径中获取文件名的方法

//根据文件路径截取文件名    public String getfileName(String s) throws Exception{          s.trim();              String fileName = s.substring(s.lastIndexOf("/")+1);             //或者            String fileName = s.substring(s.lastIndexOf("\\")+1