美文网首页知识点
iOS 从url中获取文件名以及后缀

iOS 从url中获取文件名以及后缀

作者: yangli | 来源:发表于2018-12-05 10:27 被阅读0次

    完整路径

    NSString* index=@"/var/mobile/Containers/Data/Application/45471D33-E611-499D-AFA1-856880F47549/Documents/1543976290.wav";
    

    对路径截取的9种操作

    NSLog(@"%@",[index lastPathComponent]);
    输出:1543976290.wav
    
    NSLog(@"%@",[index stringByDeletingLastPathComponent]);
    输出:/var/mobile/Containers/Data/Application/45471D33-E611-499D-AFA1-856880F47549/Documents
    
    NSLog(@"%@",[index pathExtension]);
    输出:wav
    
    NSLog(@"%@",[index stringByDeletingPathExtension]);
    输出:/var/mobile/Containers/Data/Application/45471D33-E611-499D-AFA1-856880F47549/Documents/1543976290
    
    NSLog(@"%@",[index stringByAbbreviatingWithTildeInPath]);
    输出:~/Documents/1543976290.wav
    
    NSLog(@"%@",[index stringByExpandingTildeInPath]);
    输出:/var/mobile/Containers/Data/Application/45471D33-E611-499D-AFA1-856880F47549/Documents/1543976290.wav
    
    NSLog(@"%@",[index stringByStandardizingPath]);
    输出:/var/mobile/Containers/Data/Application/45471D33-E611-499D-AFA1-856880F47549/Documents/1543976290.wav
    
    NSLog(@"%@",[index stringByResolvingSymlinksInPath]);
    输出:/var/mobile/Containers/Data/Application/45471D33-E611-499D-AFA1-856880F47549/Documents/1543976290.wav
    
    NSLog(@"%@",[[index lastPathComponent] stringByDeletingPathExtension]);
    输出:1543976290

    相关文章

      网友评论

        本文标题:iOS 从url中获取文件名以及后缀

        本文链接:https://www.haomeiwen.com/subject/urlicqtx.html