How to change the name of an environment variable with a different variable?

前端 未结 2 1904
[愿得一人]
[愿得一人] 2021-01-25 04:12

Is there a method to name an environment variable dynamically using another environment variable in a batch file?

Something like

numplayers=3
char%numpla         


        
2条回答
  •  北海茫月
    2021-01-25 04:48

    Given that you are unlikely to know beforehand the number assigned to %numplayers%, here are a few ways you can see the value of the variable:

    Set "numplayers=3"
    Set "char%numplayers%atk=12"
    Call Echo %%char%numplayers%atk%%
    

     

    Set "numplayers=3"
    Set "char%numplayers%atk=12"
    Set char%numplayers%atk
    

     

    SetLocal EnableDelayedExpansion
    Set "numplayers=3"
    Set "char%numplayers%atk=12"
    Echo !char%numplayers%atk!
    

提交回复
热议问题