I'm trying to compare a sequence of 9 numbers (separated by ,
) using a batch file.
The comparison is always made by the corresponding sequence like:
mPrevious[0] <-> mCurrent[0]
mPrevious[1] <-> mCurrent[1]
I need to know if at least one sequece have changed. In the example bellow, 234
changed to 230
and 146
to 149
.
到目前为止,我的草图是:
setlocal ENABLEDELAYEDEXPANSION
@echo off
set mPrevious=229,234,235,127,58,0,131,133,146
set mCurrent=229,230,235,127,58,0,131,133,149
for /f "tokens=1,2,3,4,5,6,7,8,9 delims=," %%a IN ('echo !mPrevious!') do (
)
条目数(当前为9)将来可能会更改。但目前他们只有9岁。
我不确定在批处理脚本中执行此操作的正确方法是什么。
让我分享我的方法,并且我不是该方法的作者。 这是在cmd / bat中定义/使用数组的安全方法。
I saw this on dostips.com /by @Aacini and after here /by @user6811411 (removed user), some time ago. The original layout code is some like:
Set "var=%var:,="&Set /a i+=1&Set "var[!i!]=%
I prefer replace
[ ]
to one simple_
Also, change
i+=
to_i+=1+0
, where no need predefinedset
command:set i=0
输出结果:
There is also another answer about this method here: