1

Okay so let's say I have the following code

set playerlevel=5
set x=player
echo %x%level

I want the output to be "5", is that possible?

2 Answers 2

3

dbmitch's answer is good for integers, but if you want to display strings or integers, you can simply use delayed expansion.

@echo off
setlocal enabledelayedexpansion

set playerlevel=5
set x=player
echo !%x%level!

Note that if the code is located inside of a code block (i.e. enclosed in parentheses), the syntax is slightly different.

@echo off
setlocal enabledelayedexpansion

REM This is just an example code block to show off the alternate syntax with the %%s
for /L %%A in (1,1,1) do (
    set playerlevel=5
    set x=player
    call echo %%!x!level%%
)
Sign up to request clarification or add additional context in comments.

Comments

2

You can get what you want by using a combination of enabledelayedexpansion and the set /a to emulate an EVAL function

Try this:

@echo off
setlocal enabledelayedexpansion

set playerlevel=5
set x=player

set /a varx = "%x%level"
echo %varx%

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.