Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Array name in a variable?

May
12,845
164
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
 
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
 
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

Back
Top