C# 修剪应用程序路径
我有这个应用程序路径:
C:\Documents and Settings\david\My Documents\app\
和文件路径:
C:\Documents and Settings\david\My Documents\app\stuff\file.txt
如何从文件路径中修剪应用程序路径,使其变为 stuff\file.txt?原因是我正在使用的命令行工具之一不支持文件路径中的空格。
I have this application path:
C:\Documents and Settings\david\My Documents\app\
And a file path:
C:\Documents and Settings\david\My Documents\app\stuff\file.txt
How can I trim the application path from the file path so it becomes stuff\file.txt? Reason being one of the command line tools I'm using doesn't support spaces in the file path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
相关文档:
Try this:
Related documentation:
我不知道您使用的是哪个命令工具,但是如果我们将字符串/路径括在引号中,例如
“C:\ Documents and Settings \ david \ My Documents \ app \ stuff \ file.txt”,它们通常会起作用
i don't know which command tool you are using, but normally they work if we enclosed the string/ path in quotation marks like this
"C:\Documents and Settings\david\My Documents\app\stuff\file.txt"
不知道为什么普通字符串替换不起作用:
但是,如果您只是将完整路径括在引号中(
“
),大多数命令行工具都可以使用空格:Not sure why normal string replace won't do:
However, if you simply enclose the full path in quotes (
"
), most command line tools will be fine with spaces: