Batch file - variables in variables
I used a for loop to split the string with spaces. I also used a loop for each word in my variable such as var1 = this, var2 = is, var3 = a, var4 = test. It looks like this: "set var! Count! = %% A"
It works. I just need to remember this. How should I do it? Logically, I think it will look like this:% Var% Amount %%
Can someone explain to me how to get this? If I have "count" 1, what should I do to get "var1"?
+3
source to share
3 answers
There is an easy way, you need to enable slow expansion, so first place setlocal enabledelayedexpansion
and then use exclamation marks to access these variables. Your script should look like this:
@echo off
setlocal enabledelayedexpansion
:: Here comes your loops to set the variables
echo/!var%count%!
+2
source to share