I have the following for loop:
for /l %%a in (1,1,%count%) do (
<nul set /p=" %%a - "
Echo !var%%a!
)
which will display something like this:
1 - REL1206
2 - REL1302
3 - REL1306
I need to create a variable that appends itself based on the number of iterations. Example the variable would look like this after the for loop:
myVar="1, 2, 3"
Use delayed expansion
setlocal enableextensions enabledelayedexpansion
SET OUTPUTSTRING=
for /l %%a in (1,1,%count%) do (
<nul set /p=" %%a - "
Echo !var%%a!
if .!OUTPUTSTRING!==. (
SET OUTPUTSTRING=%%a
) ELSE (
SET OUTPUTSTRING=!OUTPUTSTRING!, %%a
)
)
SET OUTPUTSTRING
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With