通过批处理接受基于通配符变量的用户输入



我不知道如何表达这个问题,所以你们能理解,但请耐心等待。下面是我的代码:

set var1=yes no ok get out of here exit quit
echo Do you want to start?
set /p options=Your Input:
if "%Options%" (This is what I need help with)

将用户输入与var1进行比较,如果为true,转到下一个问题即使用户输入"Go start",它也会将Go或start与var1匹配。由于Go不在列表中,它会尝试将Start与var1相匹配。如果找到,继续下一个问题。希望这是有意义的

for %%a in (%options%) do for %%b in (%var1%) do if /i "%%a"=="%%b" goto nextq
:not_found
response "%options%" is not implemented
pause

代码证明:

c:106x>q34542866
Do you want to start?
Your Input:go
User input was "go"
response "go" is not implemented
c:106x>q34542866
Do you want to start?
Your Input:no
User input was "no"
response "no" found
c:106x>q34542866
Do you want to start?
Your Input:exit
User input was "exit"
response "exit" found
c:106x>q34542866
Do you want to start?
Your Input:go start
User input was "go start"
response "go start" is not implemented
c:106x>q34542866
Do you want to start?
Your Input:I do want to start, yes please
User input was "I do want to start, yes please"
response "I do want to start, yes please" found

代码:

set var1=yes no ok get out of here exit quit
echo Do you want to start?
set /p options=Your Input:
ECHO User input was "%options%"
for %%a in (%options%) do for %%b in (%var1%) do if /i "%%a"=="%%b" goto nextq
:not_found
ECHO response "%options%" is not implemented
GOTO :EOF
:nextq
ECHO response "%options%" found
GOTO :EOF
@echo off
setlocal EnableDelayedExpansion
set "var1= yes no ok get out of here exit quit "
echo Do you want to start?
set /p options=Your Input:
for %%a in (%options%) do if "!var1: %%a =!" neq "%var1%" goto nextquestion
echo Word not found...
goto :EOF
:nextquestion
echo Word found

相关内容

  • 没有找到相关文章

最新更新