How to pass a string with spaces in it as start arguments for a program

☆樱花仙子☆ 提交于 2020-07-08 06:59:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!