I want to echo one element that the user choses from a premade array. So if the user writes a 2, I want to echo the second element of the array.
This is my code simplified. I have tried using the user input directly and converting it to int, but none of those options work.
@echo off
setlocal EnableDelayedExpansion
set test[1]=a
set test[2]=b
set test[3]=c
set test[4]=d
set /p number="Select array element: "
set /a numberAux=!number!+0
echo: 1.: !test[2]!
echo: 2.: !test[%%number]!
echo: 3.: !test[%%numberAux]!
timeout /t 3 /nobreak > NUL
endlocal
This is the output:
Select array element: 2
1.: b
2.:
3.: