Reputation: 678
I have tried to insert a dynamic string in a static string with double quote, also tried How to add double quotes to a string that is inside a variable? but nothing work in my case:
startInfo.Arguments = @"/C = """+service+""" >nul 2>&1";
service is dynamic string and i need this result:
"/C = "mystring" >nul 2>&1";
Without dynamic variable i use double quote and it work, and i need @ for static Path
"/C = ""static"" >nul 2>&1";
Upvotes: 2
Views: 171
Reputation: 7213
if (your c# version < c#6)
use string.Format()
method:
startInfo.Arguments = string.Format(@"/C = ""{0}"" >nul 2>&1", service);
you still can use +
if you want:
startInfo.Arguments = @"/C = """+ 111 +"\" >nul 2>&1";
or even:
startInfo.Arguments = @"/C = """+ 111 + @""" >nul 2>&1";
Upvotes: 2
Reputation: 101681
The verbatim string only applies to the first part because you are concetanating with +
, you can try using string interpolation:
startInfo.Arguments = $@"/C = ""{service}"" >nul 2>&1";
Upvotes: 7