Spaces in command line argument

I need to parse the argument for a string and contain spaces, so this is what I did:

search.exe "/SASE Lab Tools"

So now I have declared this as a string:

        string type = string.Format("{0}", args[0]);

then

I need to do this:

p.StartInfo.Arguments = "-R -H -h sinsscm01.ds.net " + type;

but my result contains spaces in mine p.StartInfo.Arguments.

when I need for my output for p.StartInfo.Arguments:

-R -H -h sinsscm01.ds.jdsu.net "/SASE Lab Tools"

how to add " "to your code?

+3
source share
3 answers

You need to include them in the format string, for example.

string type = string.Format("\"{0}\"", args[0]);

Or just use concatenation:

string type = "\"" + args[0] + "\"";

Currently, your format string efficiently does:

string type = args[0];
+4
source

Not sure if this will help you:

p.StartInfo.Arguments = "-R -H -h sinsscm01.ds.net \"" + type + "\"";
+1
source

, . \t , \" ..

+1

All Articles