NSPathUtilities,關于文件路徑的幾個常用操作
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); </pre><br />
運行結果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 </pre><br />
本文由用戶 emxm 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!