将包含 URL 的 NSString 转换为 POSIX 路径
我正在努力将文件或文件夹拖放到 NSPathControl 上后检索文件夹或文件的 POSIX 路径。
我是初学者,但我能够以这种方式从代码中的控件(称为 Destination
)获取值:
NSString *filepath;
filepath = [Destination stringValue];
这给了我类似的东西,
file://test/My%20New%20Project/
但我想将它放在 POSIX 中路径形式:
/test/My New Projectbecause I need to pass it to a
NSTask
running a command-line program.关于如何将此 NSString
的内容从 URL 格式转换为 POSIX 路径,有什么建议吗?
I'm working on retrieving a POSIX path to a folder or file from an NSPathControl
after dropping the file or folder onto it.
I'm a beginner, but I was able to get the value from the control (called Destination
) in my code this way:
NSString *filepath;
filepath = [Destination stringValue];
This gives me something like
file://test/My%20New%20Project/
but I'd like to have it in the POSIX path form:
/test/My New Project
because I need to pass it to a NSTask
running a command-line program.
Any suggestion about how to convert the content of this NSString
from an URL format to a POSIX path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
-URL
而不是-stringValue
。这将返回一个NSURL
对象,表示路径控件显示的路径。然后,您可以将-path
发送到NSURL
对象,以获取其字符串表示形式,而无需 URL 方案/转义。例如:或
Use
-URL
instead of-stringValue
. That will return anNSURL
object representing the path displayed by the path control. You can then send-path
to theNSURL
object to obtain its string representation without the URL scheme/escaping. For instance:or