iOS 字符串路径相关Api

截取文件路径相关的 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)