stringByDeletingLastPathComponent
ファイルパスの最後の部分(/より後)を削除した文字列を作って返します
解説
ファイルパスの最後の部分(/より後)を削除した文字列を作って返します
レシーバの文字列値 | 結果 | |
"/tmp/scratch.tiff" | -> | "/tmp" |
"/tmp/lock/" | -> | "/tmp" |
"/tmp/" | -> | "/" |
"/tmp" | -> | "/" |
"/" | -> | "/" |
"scratch.tiff" | -> | "" (空の文字列) |
返り値
( NSString * )
最後の項目を削除したパス文字列
フレームワーク
Foundation
クラス
NSString
Instance Methods
使用可能
10.0
参照
- stringByDeletingPathExtension
例文
#pragma mark iOS NSString stringByDeletingLastPathComponent -(void)method009 { NSString *str1 = [[NSString alloc] initWithString:@"/tmp/scratch.tiff"]; NSLog(@"%s %p , %@",__FUNCTION__,str1,[str1 stringByDeletingLastPathComponent]); //=>-[OOOAppDelegate method009] 0x5800 , /tmp NSString *str2 = [[NSString alloc] initWithString:@"/tmp/lock/"]; NSLog(@"%s %p , %@",__FUNCTION__,str2,[str2 stringByDeletingLastPathComponent]); //=>-[OOOAppDelegate method009] 0x5890 , /tmp NSString *str3 = [[NSString alloc] initWithString:@"/tmp/"]; NSLog(@"%s %p , %@",__FUNCTION__,str3,[str3 stringByDeletingLastPathComponent]); //=>-[OOOAppDelegate method009] 0x5830 , / NSString *str4 = [[NSString alloc] initWithString:@"/tmp"]; NSLog(@"%s %p , %@",__FUNCTION__,str4,[str4 stringByDeletingLastPathComponent]); //=>-[OOOAppDelegate method009] 0x5860 , / NSString *str5 = [[NSString alloc] initWithString:@"/"]; NSLog(@"%s %p , %@",__FUNCTION__,str5,[str5 stringByDeletingLastPathComponent]); //=>-[OOOAppDelegate method009] 0x5850 , / NSString *str6 = [[NSString alloc] initWithString:@"scratch.tiff"]; NSLog(@"%s %p , %@",__FUNCTION__,str6,[str6 stringByDeletingLastPathComponent]); //=>-[OOOAppDelegate method009] 0x5870 , (空の文字列) }