【发布时间】:2020-06-17 16:54:27
【问题描述】:
我们已经开发了一个生成支付链接的程序,我们有一个问题,参数是通过命令行参数传递的,但是如果参数字符串包含空格,它会跳转到下一个字段。
我们可以执行以下操作来解决此问题吗?如果有怎么办?
-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;
【问题讨论】:
-
我想shell确实可以很好地处理双引号。因为这也是操作系统通过长路径所做的事情。应该可以工作,你试过了吗,发生了什么?
-
我强烈建议您使用命令行解析(如 commandline)或完整的 CLI 框架(如 CliFx)来避免必须正确解析命令行参数的麻烦