zoukankan      html  css  js  c++  java
  • stringByAppendingPathComponent和stringByAppendingString 的区别

     

    stringByAppendingPathComponent和stringByAppendingString 的区别

     

    stringByAppendingPathComponent

     
    1. NSString * filePath3 = [documentsPath stringByAppendingPathComponent:@"Dictionary"];  

    stringByAppendingString


     
    1. NSString * filePath = [documentsPath stringByAppendingString:@"/hello.txt"];  

    两者比较  

    1、后者需要加"/" ,前者不需要加

    2、前者路径打印出来:/Users/MyMacBook/Library/Developer/CoreSimulator/Devices/C1B4AFE9-2058-40A6-B868-101E166FF961/data/Containers/Data/Application/79CB8A9F-1000-4360-A9EA-801ADF1E0044/Documents/DataBase.sqlite
          后者路径打印出来:/Users/MyMacBook/Library/Developer/CoreSimulator/Devices/C1B4AFE9-2058-40A6-B868-101E166FF961/data/Containers/Data/Application/79CB8A9F-1000-4360-A9EA-801ADF1E0044/Documents

    stringByAppendingPathComponent

    就是将前面的路径格式和后面的普通的字符串格式链接在一起,并且以路径格式返回。

    例如:获取程序家目录NSString *path =NSHomeDirectory();获取后的path是"/root/User/";执行

    path = [path stringByAppendingPathComponent:@"abc.txt"];后path为“/root/User/abc.txt”。




  • 相关阅读:
    Educational Codeforces Round 80 (Rated for Div. 2)
    2020 CCPC Wannafly Winter Camp
    Codeforces Round #613 (Div. 2)
    Codeforces Round #612 (Div. 2)
    Hello 2020
    Good Bye 2019
    Codeforces Round #590 (Div. 3)
    依赖注入
    Spring 拦截器
    rsync服务端一键安装rsync脚本(非源码)
  • 原文地址:https://www.cnblogs.com/LiLihongqiang/p/5912683.html
Copyright © 2011-2022 走看看