Array name in a variable?

May 20, 2008
11,926
124
Syracuse, NY, USA
Is there a syntax which will allow me to reference an element of an array when I have the name of that array in a variable? Here's a simple partial example.
Code:
:showarray [arrayname]
echo ???????[0] & rem What do I put here if I want to see the 0th element in the array?
return
 
May 20, 2008
11,926
124
Syracuse, NY, USA
Is there a syntax which will allow me to reference an element of an array when I have the name of that array in a variable? Here's a simple partial example.
Code:
:showarray [arrayname]
echo ???????[0] & rem What do I put here if I want to see the 0th element in the array?
return
It's a workaround, but this works.
Code:
:showarray [arrayname]
set b=%%%arrayname[0]
echo %b
return

Here it is explicitly.
Code:
v:\> setarray a[1]

v:\> set a[0]=foo

v:\> set arrayname=a

v:\> echo %%%arrayname[0]
%a[0]

v:\> set b=%%%arrayname[0]

v:\> set b
%a[0]

v:\> echo %b
foo
 
May 20, 2008
11,926
124
Syracuse, NY, USA
Well, you *could* do that, but this is simpler:

Code:
setarray a[1]
set a[0]=foo
set arrayname=a
echo %[arrayname[0]]
Thanks! I tries many (often bizarre) constructions but not that one. Now that I see it, it makes sense.
 

Similar threads