C# 如何将带有空格的字符串作为程序的开始参数传递
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11085023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pass a string with spaces in it as start arguments for a program
提问by Simon
I have a console project which I want to start with some parameters argc. I want to pass to it a path from my computer, let's say C:\\My Folder. How can I pass the spaces?
我有一个控制台项目,我想从一些参数开始argc。我想从我的计算机向它传递一条路径,比方说C:\\My Folder。我怎样才能通过空格?
When I try to read it I obtain something like C:\\My. I've read that I can pass them by using ". If so, how can I pass those to a string ("C:\My Folder") because I am start this program by using the Process.Startand ProcessStartInfocommands?
当我尝试阅读它时,我获得了类似C:\\My. 我读过我可以通过使用". 如果是这样,我如何将它们传递给字符串 ( "C:\My Folder"),因为我是使用Process.Start和ProcessStartInfo命令启动该程序的?
采纳答案by bluevector
Wrap the argument in double quotes:
用双引号将参数括起来:
"c:\My Folder\some.exe" /a="this is an argument"
As a string passed to Process.Start:
作为传递给 Process.Start 的字符串:
process.StartInfo.Aguments = "\"this is an argument\"";
Check out this post & answerfor more details.
查看此帖子并回答以获取更多详细信息。
回答by sudhAnsu63
You can use delimited string. Using delimited string you can pass space, new line, or any other characters like slash , backslash etc.
您可以使用分隔字符串。使用分隔字符串,您可以传递空格、换行符或任何其他字符,如 slash 、反斜杠等。
example: string path = @"\"C:\My Folder\"";
string name = @" sudhansu sekhar";

