2

I want to set a variable that uses another variable in its name. I want to do something like:

set a=2
set b=0
set s%a%%b%=Yee

Obviously, this doesn't work, but I want to be able to call the variable by doing:

echo %s20%

So it would echo Yee. This may be something you can't do, but it would make setting lots of variables much easier.

bella
  • 25
  • 1
  • 5
  • 1
    The concept you use is called _array_. See: http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990 – Aacini Sep 02 '15 at 18:41

1 Answers1

3
@echo off
set a=2
set b=0
set s%a%%b%=Yee


call echo %%s%a%%b%%%
:: OR ::
setlocal enableDelayedExpansion

echo !s%a%%b%!

endlocal

Better use the way with the delayed expansion as the call hits the performance.

npocmaka
  • 55,367
  • 18
  • 148
  • 187