I have the following FOR /F Loop and I would like to format the SET command based on a known value of "count" variable.
For example, inside the FOR /F Loop:
- If count value = 1 the set command will look like: "set c1=%%A"
- If count value = 2 the set command will look like: "set c1=%%A &set c2=%%B"
- If count value = 3 the set command will look like: "set c1=%%A &set c2=%%B &set c3=%%C"
etc.
Code: Select all
@echo off
set "inputTokens=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26"
set count=3
for /f "tokens=1-26* delims=," %%A in (%inputTokens%) do (
if "%count%" equ "1" (set c1=%%A)
if "%count%" equ "2" (set c1=%%A &set c2=%%B)
if "%count%" equ "3" (set c1=%%A &set c2=%%B &set c3=%%C)
if "%count%" equ "4" (set c1=%%A &set c2=%%B &set c3=%%C &set c4=%%D)
if "%count%" equ "5" (set c1=%%A &set c2=%%B &set c3=%%C &set c4=%%D &set c5=%%E)
...
)
I wonder if there is any shorter way to format the set command instead of listing all 26 possibilities for it.