删除 NSString 路径字符串

发布于 2024-12-20 14:05:08 字数 101 浏览 1 评论 0原文

我有一个看起来像 /test/test1/test2 的 NSString。我如何删除 test2,知道它可以以任何其他方式命名?谢谢!

I have a NSString which looks like /test/test1/test2. How could I delete the test2, knowing that it can be named in any other way? Thanks!

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

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

发布评论

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

评论(2

滥情空心 2024-12-27 14:05:08

听起来你正在寻找 NSString 的 stringByDeletingLastPathComponent 方法(文档为您链接)。

Sounds like you are looking for NSString's stringByDeletingLastPathComponent method (documentation linked for you).

戏蝶舞 2024-12-27 14:05:08

NSString 方法 - (NSString *)stringByDeletingLastPathComponent 会做你想做的事 想。

但需要注意的是,它将把“/foo/bar/”变成“/foo/”,这可能是也可能不是理想的。

The NSString method - (NSString *)stringByDeletingLastPathComponent will do what you want.

One note though, it will turn "/foo/bar/" into "/foo/" which may or may not be desirable.

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