Passing command-line arguments in C#

I just ran a check and verified the problem. It surprised me, but it is the last \ in the first argument.

"C:\Program Files\Application name\" <== remove the last '\'

This needs more explanation, does anybody have an idea? I’m inclined to call it a bug.


Part 2, I ran a few more tests and

"X:\\aa aa\\" "X:\\aa aa\" next

becomes

X:\\aa aa\
X:\\aa aa" next

A little Google action gives some insight from a blog by Jon Galloway, the basic rules are:

  • the backslash is the escape character
  • always escape quotes
  • only escape backslashes when they precede a quote.

Leave a Comment