标签:nspathutilities 文件路径 扩展名 拼接路径 extension
NSPathUtilities,关于文件路径的几个常用操作,熟悉一下,拼接路径什么的,感觉还是挺好使的。
//原路径。随便在项目中添加了张图片,用于测试 NSString *strPath =[[NSBundle mainBundle] pathForResource:@"002" ofType:@"png"]; NSLog(@"path======%@", strPath); //获取路径的最后一层 NSString *strAllName = [strPath lastPathComponent]; NSLog(@"allName===%@",strAllName); //去掉路径的最后一层 NSString *strFilePath = [strPath stringByDeletingLastPathComponent]; NSLog(@"filePath==%@",strFilePath); //去掉扩展名 NSString *strName = [strAllName stringByDeletingPathExtension]; NSLog(@"strName===%@",strName); //获取扩展名 NSString *strExtension = [strPath pathExtension]; NSLog(@"extension=%@",strExtension);
运行结果 2015-05-06 18:20:48.638 test03[3470:1708111] path======/private/var/mobile/Containers/Bundle/Application/9A142EC0-A29F-42DF-AFF6-C36E448271AE/test03.app/002.png 2015-05-06 18:20:48.639 test03[3470:1708111] allName===002.png 2015-05-06 18:20:48.640 test03[3470:1708111] filePath==/private/var/mobile/Containers/Bundle/Application/9A142EC0-A29F-42DF-AFF6-C36E448271AE/test03.app 2015-05-06 18:20:48.640 test03[3470:1708111] strName===002 2015-05-06 18:20:48.641 test03[3470:1708111] extension=png
标签:nspathutilities 文件路径 扩展名 拼接路径 extension
原文地址:http://blog.csdn.net/u011439689/article/details/45539027