Split string containing command-line parameters into string[] in C# -
I have a string that contains command-line parameters to pass the second executable and I need to remove the string [] In which the same criteria are included, if the command line is specified on the command line in C #, the string [] will be used when other assembly entry points will be executed through reflection.
Is this a standard work? Or is there any preferred method (regex?) To correctly divide the parameters? It should handle the '' delimited strings in which the spaces may be correct, so I can not just divide ''. Example string:
string parameter string = @ "/ Src:" "C: \ tmp \ some folder \ sub folder" "/ users:" " Abcdefg@hijkl.com "" Job: "" Some Tasks, Some Other Tasks "" -Somaparam Fu "; Example of the result: string [] parameter array = new string [] {@ "/ src: c: \ tmp \ some folder \ sub folder ", @" / User: abcdefg@hijkl.com ", @" Job: some tasks, some other tasks ", @" - some paragraph ", @" afu "};
I do not need a command line The parsing library is a way to get only [string] that must be generated.
Update : I had to change the expected result for the match that was generated by C # in the split string "extra")
LPWSTR * CommandLineToArgvW (LPCWSTR lpCmdLine, int * pNumArgs);
Parse a Unicode command line string and provides an array of points for command line arguments, with the count of such arguments, which are similar to the standard C run-time Argv and argc value
An example of calling this API from C # and opening the resulting string array in the managed code can be found, "Below" is a slightly simpler version of the same code:
[DllImport ("shell32.dll", SetLastError = true)) static extern IntPtr CommandLineToArgvW ([MarshalAs (UnmanagedType.LPWStr)] string lpCmdLine, out int pNumArgs); Public static string [] command line taorge (string commandline) {int argc; Var argv = CommandLineToArgvW (command line, outside argc); Throw the new system (argv == IntPtr.Zero). ComponentModel.Win32Exception (); Try {var args = new string [argc]; (Var i = 0; i & lt; argsLength; i ++) {var p = martial. Readprint (argv, i * IntPtr.Size); Args [ii] = martial.printstringonly (p); } Return logic; } Finally {Martial. Freih Global (argv); }}
Comments
Post a Comment