我怎么称呼动态变量名? [英] How would I call a dynamic variable name?

查看:53
本文介绍了我怎么称呼动态变量名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我正在尝试制作一个理解"用户输入并按照用户要求执行的程序.人们通常只使用特定的命令,例如打开此文件",并且只有在用户键入完全相同的命令时它才起作用.我试图给我的用户一些余地,以便他们可以键入他们想要发生的事情,然后计算机将获得一般的想法.撇开那堆杂乱无章的东西,我遇到了一个问题.

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?

推荐答案

在脚本的开头添加 setLocal enableDelayedExpansion .

然后将 echo%word%var %% 替换为 echo!word%var%!.

更多信息- http://ss64.com/nt/delayedexpansion.html

这篇关于我怎么称呼动态变量名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆