I need to access the commandline from within a C# application. I can't find a way to detect mismatched double quotes if I use the "args" parameter.
The application I'm working on the moment has an option to encrypt a string that you pass to it via the commandline.
eg.
program.exe -encrypt somestring
Results in:
EZs/6rWxvJ82+VE8unJ0Xw==
Now if the user types in this:
program.exe -encrypt somestring extra characters
it ignores everything after "somestring" (you can still access the rest of the values through the "args" parameter).
You can workaround this easily using double quotes:
program.exe -encrypt "somestring extra characters"
And of course if you want to use embedded quotes you can escape them with "\":
program.exe -encrypt "somestring \"extra\" characters"
The problem occurs when the user inputs something like this:
program.exe -encrypt "somestring extra characters
or:
program.exe -encrypt somestring ex"tra characters
The program will completely ignore the double quote, which not be what the user was expecting. I would like to detect cases like these and inform the user about the mismatched/unescaped quote, otherwise they might end up with an encrypted version of the wrong string.