美文网首页
iOS 字符串路径相关Api

iOS 字符串路径相关Api

作者: Magician | 来源:发表于2017-09-30 13:39 被阅读12次

    截取文件路径相关的 Api

        // 数据库路径
        NSString *url = @"/Users/Dalang/Library/Developer/CoreSimulator/Devices/62D1B0C1-310F-4934-81C7-433F03EBC907/data/Containers/Data/Application/A7802BF0-67C9-46BC-9E26-943A3132DD5B/Documents/SharkDB/Shark-233.db";
        
        NSLog(@"%@",[url lastPathComponent]);
        // Shark-233.db
        
        NSLog(@"%@",[url stringByDeletingLastPathComponent]);
        // /Users/Dalang/Library/Developer/CoreSimulator/Devices/62D1B0C1-310F-4934-81C7-433F03EBC907/data/Containers/Data/Application/A7802BF0-67C9-46BC-9E26-943A3132DD5B/Documents/SharkDB
        
        NSLog(@"%@",[url pathExtension]);
        // db
        
        NSLog(@"%@",[url stringByDeletingPathExtension]);
        // /Users/Dalang/Library/Developer/CoreSimulator/Devices/62D1B0C1-310F-4934-81C7-433F03EBC907/data/Containers/Data/Application/A7802BF0-67C9-46BC-9E26-943A3132DD5B/Documents/SharkDB/Shark-233
        
        NSLog(@"%@",[url stringByAbbreviatingWithTildeInPath]);
        // /Users/Dalang/Library/Developer/CoreSimulator/Devices/62D1B0C1-310F-4934-81C7-433F03EBC907/data/Containers/Data/Application/A7802BF0-67C9-46BC-9E26-943A3132DD5B/Documents/SharkDB/Shark-233.db
        
        NSLog(@"%@",[url stringByExpandingTildeInPath]);
        // /Users/Dalang/Library/Developer/CoreSimulator/Devices/62D1B0C1-310F-4934-81C7-433F03EBC907/data/Containers/Data/Application/A7802BF0-67C9-46BC-9E26-943A3132DD5B/Documents/SharkDB/Shark-233.db
        
        NSLog(@"%@",[url stringByStandardizingPath]);
        // /Users/Dalang/Library/Developer/CoreSimulator/Devices/62D1B0C1-310F-4934-81C7-433F03EBC907/data/Containers/Data/Application/A7802BF0-67C9-46BC-9E26-943A3132DD5B/Documents/SharkDB/Shark-233.db
        
        NSLog(@"%@",[url stringByResolvingSymlinksInPath]);
        // /Users/Dalang/Library/Developer/CoreSimulator/Devices/62D1B0C1-310F-4934-81C7-433F03EBC907/data/Containers/Data/Application/A7802BF0-67C9-46BC-9E26-943A3132DD5B/Documents/SharkDB/Shark-233.db
        
        NSLog(@"%@",[[url lastPathComponent] stringByDeletingPathExtension]);
        // Shark-233
    

    相关文章

      网友评论

          本文标题:iOS 字符串路径相关Api

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