#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSMutableArray *arr=[[NSMutableArray alloc]init]; NSString *str=@"/Users/apple/Desktop/企業項目";//桌面一個文件夾路徑 [arr addObject:str];//往數組添加對象 NSString *path=[arr objectAtIndex:0]; NSLog(@"path:%@",path);//path:/Users/apple/Desktop/企業項目 NSLog(@"str:%@",str);//str:/Users/apple/Desktop/企業項目 } return 0; } #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSString *path=@"/Users/apple/Desktop/App Su"; NSArray *arr=[path componentsSeparatedByString:@"/"]; NSLog(@"arr:%@",arr); /* arr:( "", Users, apple, Desktop, "App Su" ) */ NSString *str=[arr lastObject]; NSLog(@"str:%@",str);//str:App Su } return 0; }