Code: Select all
set get_element=^
for /l %%N in (1 1 2) do if %%N equ 2 (^
for /f "tokens=1-3 delims= " %%A in ("^!args^!") do (^
for /f "tokens=%%B delims=," %%X in (^!%%A^!) do (^
set "%%C=%%X"^
)^
)^
) else set args=
set lst="one,two,three"
%get_element% lst 2 el
echo,el: [%el%]
%B delims=," was unexpected at this time.
el: []
A function that does the same thing, however, does work:
Code: Select all
:GetElement
for /f "tokens=%2 delims=," %%a in (!%1!) do (
set %3=%%a
)
exit /b