问题
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?
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.Start
and ProcessStartInfo
commands?
回答1:
Wrap the argument in double quotes:
"c:\My Folder\some.exe" /a="this is an argument"
As a string passed to Process.Start:
process.StartInfo.Aguments = "\"this is an argument\"";
Check out this post & answer for more details.
回答2:
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";
来源:https://stackoverflow.com/questions/11085023/how-to-pass-a-string-with-spaces-in-it-as-start-arguments-for-a-program