我試圖做一個批處理文件,通過一個數組,包含這樣的數字循環:1 2 3 4 5. 在循環的第一個循環中,我喜歡挑選標記1和2.在第二和第三,第三和第四,等等。變量作爲令牌的for循環
我認爲我應該使用!在我用作令牌的第一個和第二個變量中。像第一個FOR/F一樣,但是當我這樣做時,我得到了:!第一!「在這裏沒有預料到
如果我使用%,它不會計數 除了變量標記之外, ?一個knowes如何任何幫助或建議大大appriciated 這是部Im struggeling有:
setlocal EnableDelayedExpansion
set first=1
set second=2
set N=4
set output="1 2 3 4 5"
set output=%output:"=%
for /L %%a in (1,1,%N%) do (
if !counter! equ active (
set /a first+=1
set /a second+=1
)
FOR /F "tokens=!first!" %%a IN ("%output%") DO (
set nr1=%%a
)
FOR /F "tokens=%second%" %%a IN ("%output%") DO (
set nr2=%%a
)
echo nr1 var: !nr1!
echo nr2 var: !nr2!
echo counter f: !first!
echo counter s: !second!
set counter=active
)