我有以下问题。我正在从数据库中读取字段。这些字段并非都是强制性的。因此,并非所有这些都已填写。我遇到的问题是批处理(ms dos)和令牌功能。
举个例子:
有问题的字段如下:(例子)
First Name: John
Last Name: Smith
Address: 123 Fake Street
Postal Code: 45612
Company: SomeCo
Department: Accounting
Floor: 4
Phone: 123-555-5555
Mobile: 123-555-5556
当我运行此代码时:
FOR /F "tokens=1-9, delims=," %%a in (info_file.txt) DO echo %%a, %%b, %%c, %%d, %%e, %%f, %%g, %%h, %%i
输出将如下所示:
%%a= John
%%b= Smith
%%c= 123 Fake Street
%%d= 45612
%%e= SomeCo
%%f= Accounting
%%g= 4
%%h= 123-555-5555
%%i= 123-555-5556
一切都很好。我正确显示了所有回声。但!如果缺少这些字段中的任何一个,例如:
First Name: John
Last Name: Smith
Address: 123 Fake Street
Postal Code: <missing info; consider this line blank>
Company: SomeCo
Department: <missing info; consider this line blank>
Floor: 4
Phone: 123-555-5555
Mobile: 123-555-5556
我的输出如下所示:
%%a= John
%%b= Smith
%%c= 123 Fake Street
%%d= SomeCo
%%e= 4
%%f= 123-555-5555
%%g= 123-555-5556
%%h= <not used; Because there is not enough lines available>
%%i= <not used; Because there is not enough lines available>
您可以看到这如何导致挫败感。
我的问题是:如何确保所有内容%%<variables>
始终对齐,即使该空间中的信息为空白?