lastPathComponent
ファイルパスの最後の部分(/より後)を返します
解説
ファイルパスの最後の部分(/より後)を返します
レシーバーの文字列値 返される文字列
"/tmp/scratch.tiff" ->"scratch.tiff"
"/tmp/scratch" ->"scratch"
"/tmp/" ->"tmp"
"scratch" ->"scratch"
"/" ->"/"
返り値
( NSString * )
ファイル名
引数
フレームワーク
Foundation
クラス
NSString
Instance Methods
使用可能
10.0
参照
例文
NSString *stringValue = [theNode lastPathComponent]; //ファイルが見えるかを返す(最初が.なら非表示) - (BOOL)isVisible { NSString *lastPathComp = [self lastPathComponent]; return ([lastPathComp length] ? ([lastPathComp characterAtIndex:0]!='.') : NO); }
#pragma mark iOS NSString lastPathComponent -(void)method007 { NSString *str1 = [[NSString alloc] initWithString:@"/tmp/scratch.tiff"]; NSLog(@"%s %p , %@",__FUNCTION__,str1,[str1 lastPathComponent]); //=>0x57d8 , scratch.tiff NSString *str2 = [[NSString alloc] initWithString:@"/tmp/scratch"]; NSLog(@"%s %p , %@",__FUNCTION__,str2,[str2 lastPathComponent]); //=>0x57f8 , scratch NSString *str3 = [[NSString alloc] initWithString:@"/tmp/"]; NSLog(@"%s %p , %@",__FUNCTION__,str3,[str3 lastPathComponent]); //=>0x5808 , tmp NSString *str4 = [[NSString alloc] initWithString:@"scratch"]; NSLog(@"%s %p , %@",__FUNCTION__,str4,[str4 lastPathComponent]); //=>0x5818 , scratch NSString *str5 = [[NSString alloc] initWithString:@"/"]; NSLog(@"%s %p , %@",__FUNCTION__,str5,[str5 lastPathComponent]); //=>0x5828 , / }