iOS 字符串路径相关Api

Posted 陌上心

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

IO[File_API学习]

IO----File类

JavaScript之切割路径并返回对应的值splitnewURLSearchParamsgeturl处理URL的查询字符串

Java IO流 简介

iOS文件路径相关的方法

当相关资源属于不同的微服务时,如何处理 REST API 路径?