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

前端 未结 2 1905
[愿得一人]
[愿得一人] 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!
    
    0 讨论(0)
  • 2021-01-25 05:01

    It's quite straightforward:

    SET numplayers=3
    SET char%numplayers%atk=12
    ECHO %char3atk%
    
    0 讨论(0)
提交回复
热议问题