NSString類路徑的處理方法:
文件路徑的處理:
NSString *path = @"/Uesrs/apple/testfile.txt"
常用方法如下:
(1)獲得組成此路徑的各個(gè)組成部分,結(jié)果:("/","User","apple","testfile.txt")
- (NSArray *)pathComponents;
(2)提取路徑的最后一個(gè)組成部分,結(jié)果:testfile.txt
-?(NSString?*)lastPathComponent;
(3)刪除路徑的最后一個(gè)組成部分,結(jié)果:/Users/apple
-?(NSString *)stringByDeletingLastPathCpmponent;
(4)添加到路徑的末尾,結(jié)果:/Users/apple/testfile.txt/app.txt
-?(NSString?*)stringByAppendingPathConmponent:(NSString?*)str;
(5)刪除路徑最后部分的擴(kuò)展名,結(jié)果:/Users/apple/testfile
-?(NSString?*)stringByDeletingPathExtension;
(6)路徑最后部分追加擴(kuò)展名,結(jié)果:/User/apple/testfile.txt.jpg
-?(NSString?*)stringByAppendingPathExtension:(NSString?*)str;