在 Objective-C 中从 txt 文件中删除一行

发布于 2024-09-04 07:36:28 字数 93 浏览 6 评论 0原文

有没有办法从 Objective-C 的 .txt 文件末尾删除一行?我似乎找不到任何关于从 Objective-C 操作文本文件的内容,只能将它们读入 NSString。

Is there a way to remove a line from the end of a .txt file from Objective-C? I can't seem to find anything on manipulating text files from Objective-C, only reading them into a NSString.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰沐子 2024-09-11 07:36:28

您是否考虑过将数据模型更改为 plist? Plist 更容易从 NSDictionaries 中读取/写入。

否则,我认为唯一的方法是将文件读入 NSString,通过拆分 \n 分成组件 NSArray,删除索引 n 处的对象,写回通过与组件 \n 连接成字符串,然后写回文件。

Have you considered changing your data model to a plist? Plists are more easily read/written into/from NSDictionaries.

Otherwise, I think the only way is to read the file into a NSString, separate into a component NSArray by splitting on \n, remove the object at index n, write back into a string by joining with component \n, then writing back to the file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文