C# 命令行参数

C# Command line argument

我们开发了一个生成支付链接的程序,我们有一个问题,参数是通过命令行参数传递的,但是如果参数的字符串包含 space,它会跳转到下一个字段。

我们可以执行以下操作来解决这个问题吗?如果有怎么办?

-Amount "agument with space 1"
-Currency "argument with space2"
-Firstname "argument with space3"
...

这是当前的代码位:

if (commandlineargs.Length > 0)
                {
                    var BEDRAG = commandlineargs[1];
                    var CURRECY = commandlineargs[2];
                    var VOORNAAM = commandlineargs[3]; 

                    var ACHTERNAAM = commandlineargs[4];
                    var EMAIL = commandlineargs[5];
                    var KLANTCODE_EN_DOCNUM = commandlineargs[6];
                    var WINKEL = commandlineargs[7]; // (see sap configuration U_webshop)                  


                    txt_bedrag.Text = BEDRAG;
                    txt_firstname.Text = VOORNAAM;
                    txt_lastname.Text = ACHTERNAAM;
                    txt_email.Text = EMAIL;
                    txt_klant_en_docnummer.Text = KLANTCODE_EN_DOCNUM;
                    txt_currency.Text = CURRECY;

将参数用双引号引起来:

-Amount "\"agument with space 1\""

查看此 post 了解更多详情。