jeremychan
jeremychan

Reputation: 4459

spaces in argument from commandline

i need to parse an argument to a string and it contains spaces so this is what i did:

search.exe "/SASE Lab Tools"

so now i 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 my p.StartInfo.Arguments.

when what i need for my output for p.StartInfo.Arguments is:

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

how do i add " " into my code?

Upvotes: 3

Views: 3002

Answers (3)

BugFinder
BugFinder

Reputation: 17858

You can add most characters with a backslash if they have other meanings. such as \t for tab, and \" will give quotes etc.

Upvotes: 1

Diogo Gomes
Diogo Gomes

Reputation: 2388

Not sure if this should help you:

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

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1500525

You need to include them in your format string, e.g.

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

Or just use concatenation:

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

Currently your format string is effectively just doing:

string type = args[0];

Upvotes: 4

Related Questions