0

When I give a path like c:\some folder with a blank into the Debug option of Visual Studio I need to escape it with a double quote " just like you would on the command line as well.

If I do it like that "c:\some folder with a blank" then the args[0] parameter is "c:\\some folder with a blank"

However, if I do it like this "c:\some folder with a blank\" then the args[0]actually contains: "c:\\some folder with a blank\"", having the final " as an actual part of the string.

The same is true for when I call it from the command line directly.

Dee J. Doena
  • 1,631
  • 3
  • 16
  • 26

1 Answers1

0

The \" is an escape sequence for ". If you want the last backslash then use the escape sequence for the backslash \\

Command line argument:

"c:\some folder with a blank\\"

And because you have last " as an escape sequence, the argument is read till the end. If you omit " at the end, you still have the whole argument.

Try these arguments yourself

"c:\some folder with a blank\

"c:\some folder \" with a blank\
T. Dominik
  • 406
  • 3
  • 13
  • But if I use `"c:\temp"` then that does not mean `"c:[tab]emp"` and `"c:\audible"` does not mean `"c:[beep]udible"` – Dee J. Doena Sep 19 '22 at 11:31
  • You are right, it seems like a special case, see [GetCommandLineArgs](https://learn.microsoft.com/en-us/dotnet/api/system.environment.getcommandlineargs?redirectedfrom=MSDN&view=net-6.0#remarks) – T. Dominik Sep 19 '22 at 12:07
  • 1
    Btw I just found the same question [Why does C# appear to partially un-escape command line arguments?](https://stackoverflow.com/questions/43359103/why-does-c-sharp-appear-to-partially-un-escape-command-line-arguments) – T. Dominik Sep 19 '22 at 12:12