First, your "\r\n" is non-portable; right end-of-line is:
System.Environment.NewLine
.
Now, I have no idea what do you mean by "????????". It must be just a blank space, " ". Also, it's safer to parse the text in separate line and get each line in quotation marks. This is for the case when you mean each line to be a separate argument. The thing is: there can be blank spaces
inside an argument.
To do it, use
string.Split
:
System.Text.StringBuilder sb = new System.Text.StringBuilder();
string[] lines = comment.Split(
new string[] {System.Environment.NewLine},
System.StringSplitOptions.RemoveEmptyEntries)
.Trim();
foreach(string line in lines)
sb.Append(string.Format(@"""{0}"" ", line);
comment = sb.ToString();
Also, never repeat string concatenation "+". Strings are immutable — do I have to explain the consequence? Especially, in your case you already use
string.Format
.
Could be:
tagProcess.StartInfo.Arguments = string.Format(@"{0} ""{1}""", tag, comment);
However, you don't need those quotation marks. Each argument optionally goes in quotation marks, not all of them together. I already put those marks in the previous code sample.
—SA