C# Command-Line Parsing of Quoted Paths and Avoiding Escape Characters

后端 未结 3 2095
[愿得一人]
[愿得一人] 2020-12-10 10:16

How is it possible to parse command-line arguments that are to be interpreted as paths? args[] contains strings that are automatically joined if they are quoted, e.g.:

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 11:14

    Not an answer, but here's some background and explanation from Jeffrey Tan, Microsoft Online Community Support (12/7/2006):

    Note: this is not not a code defeat but by design, since backslashe are normally used to escape certain special character. Also, this algorithm is the same as Win32 command line arguments parsing function CommandLineToArgvW. See the Remarks section below: http://msdn2.microsoft.com/en-us/library/bb776391.aspx

    Also makes reference to the FX method Environment.GetCommandLineArgs for further explanation of the slash handling behavior.

    Personally I think this is a drag, and I'm surprised I haven't been bit by it before. Or maybe I have and don't know it? Blind replacement of quotes with slashes doesn't strike me as a solution, though. I'm voting the question up, because it was an eye opener.

提交回复
热议问题