i need to parse 开发者_JS百科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?
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];
Not sure if this should help you:
p.StartInfo.Arguments = "-R -H -h sinsscm01.ds.net \"" + type + "\"";
You can add most characters with a backslash if they have other meanings. such as \t for tab, and \" will give quotes etc.
精彩评论