[英]How to pass a string with spaces in it as start arguments for a program
I have a console project which I want to start with some parameters argc
. 我有一个控制台项目,我想从一些参数argc
开始。 I want to pass to it a path from my computer, let's say C:\\\\My Folder
. 我想从我的计算机传递一条路径,让我们说C:\\\\My Folder
。 How can I pass the spaces? 我怎么能通过空格?
When I try to read it I obtain something like C:\\\\My
. 当我尝试阅读它时,我获得了类似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.Start
and ProcessStartInfo
commands? 我已经读过,我可以通过使用"
传递它们。 "
如果是这样,我怎么能将它们传递给字符串( "C:\\My Folder"
),因为我是通过使用Process.Start
和ProcessStartInfo
命令启动这个程序的?
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 & answer for more details. 查看此帖子和答案以获取更多详细信息。
You can use delimited string. 您可以使用分隔字符串。 Using delimited string you can pass space, new line, or any other characters like slash , backslash etc. 使用分隔字符串,您可以传递空格,换行或任何其他字符,如斜杠,反斜杠等。
example: string path = @"\"C:\\My Folder\"";
string name = @" sudhansu sekhar";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.