I can't get my head around quotes.
EG, I have a string for an mp3 with quotes:
string ARTIST = "John \"The Man\" Doe"
I then want to开发者_JS百科 pass this to a command line WITH the escape sequences. I therefore need my string to look like (I think):
ARTIST = "John \\\"The Man\\\" Doe"
So it looks like, for every time I have an (actual) "
in my string, I need \"
.
I have tried using:
ARTIST.Replace("\"","\\\"")
But this has not worked. What is the correct way to handle quotes at the command line in my application?
Make sure you are doing:
ARTIST = ARTIST.Replace("\"","\\\"");
Instead of just:
ARTIST.Replace("\"","\\\"");
Is this the case already?
The windows command line doesn't use \ as an escape for a quote, it uses a redundant quote,
so you want to send "John ""The Man"" Doe"
which you get in C# by escaping each quote
string ARTIST = "John \"\"The Man\"\" Doe"
The basic idea does seem to be correct, but did you also add the surrounding quotes, i.e.,
"\"" + ARTIST.Replace("\"", "\\\"") + "\""
Also, note that you'll need three backslashes rather than two to escape \"
; the compiler would complain if you didn't.
精彩评论