我需要一种快速的方法在bat文件中插入几行结构化数据
我使用了一个名为my array的数组来扫描和“读取”我的值,但它不起作用,我不明白为什么
这是我的代码:
@echo off
set myarray[1]=myfield1#myfield2#mysubfield31;mysubfield32#myfield4
for /f "tokens=1-9 delims=#" %%a in ('echo %myarray[1]%') do (
echo field1 is %%a
echo field2 is %%b
echo field3 is %%c
echo field4 is %%d
for /f "tokens=1-9 delims=;" %%k in ('echo %%c') do (
echo subfield3 is %%k
echo subfield3 is %%l
)
)
输出如下:
field1 is myfield1
field2 is myfield2
field3 is mysubfield31 mysubfield32
field4 is myfield4
subfield3 is mysubfield31 mysubfield32
subfield3 is
为什么我不能简单地:
subfield3 is mysubfield31
subfield3 is mysubfield32
第二个用来做分度计的“;”在哪里?
最佳答案
这工作:
@echo off
set myarray[1]=myfield1#myfield2#mysubfield31;mysubfield32#myfield4
for /f "tokens=1-9 delims=#" %%a in ("%myarray[1]%") do (
echo field1 is %%a
echo field2 is %%b
echo field3 is %%c
echo field4 is %%d
for /f "tokens=1-9 delims=;" %%k in ("%%c") do (
echo subfield3 is %%k
echo subfield3 is %%l
)
)
pause
关于windows - for循环和定界符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17390900/