How would I call a dynamic variable name?

爱⌒轻易说出口 提交于 2019-12-20 05:46:10

问题


Okay, so I'm trying to make a program that "understands" user input and does what they tell it to do. People usually just use specific commands such as "open this file" and it only works if the user types EXACTLY that. I'm trying to give my users a little bit of leeway, so that they can type something like what they want to happen, and the computer will get the general idea. With that block of rambling aside, I've run into a problem.

set word%wordNum%=%word%
:fileExtension
set extChk= %letterNum% - 2 REM Includes the period of the extension
call set extension=%%_albaiRec:~%extChk%,4%%
::extChk is checking for a period so the program will recognize a file extension
set file=

That last line is where I get stuck... I'm trying to use that last recorded word variable.

set var=7
set word7=Wanted text
echo %word%var%%

Sorta like that?


回答1:


Add setLocal enableDelayedExpansion to the start of your script.

Then replace echo %word%var%% with echo !word%var%!.

For more information - http://ss64.com/nt/delayedexpansion.html



来源:https://stackoverflow.com/questions/22621708/how-would-i-call-a-dynamic-variable-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!