概述
stringByAppendingPathComponent和stringByAppendingString 的区别
stringByAppendingPathComponent
- NSString * filePath3 = [documentsPath stringByAppendingPathComponent:@"Dictionary"];
stringByAppendingString
- 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”。
转载于:https://www.cnblogs.com/LiLihongqiang/p/5912683.html
最后
以上就是自觉乌龟为你收集整理的stringByAppendingPathComponent和stringByAppendingString 的区别stringByAppendingPathComponent和stringByAppendingString 的区别的全部内容,希望文章能够帮你解决stringByAppendingPathComponent和stringByAppendingString 的区别stringByAppendingPathComponent和stringByAppendingString 的区别所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复