希望你们感恩节过得愉快!
不管怎样,我一直在四处寻找答案,但我似乎找不到我需要的答案。
基本上,我的批处理文件有一个输入,你可以在其中写一个句子。这句话会带你去:只要里面有“陈妈妈”这个词,就改正。
@echo off
:start
set /p test=Write a sentene with the word Mommy Chan in it:
if "%test%"=="Mommy Chan" goto correct
if "%test%" NEQ "Mommy Chan" goto incorrect
:correct
cls
echo %test%
echo you did it
pause
goto start
:incorrect
cls
echo %test%
echo you didn't follow directions
pause
goto start现在,这似乎是可行的,并将您带到:如果用户输入的单词“妈妈陈”的输入正确,而没有其他。但是,如果用户输入“不是妈妈成龙”,它似乎没有意识到“妈妈成龙”这个词包含在其中,它会让你看到:不正确
显然我不想那样。
为了澄清问题,我想让你输入“妈妈陈”这个词的句子,例如:“有一天陈妈妈去购物”,它应该把你带到:更正。然而,只有当用户只输入“妈妈陈”时,它才会这样做,否则它只会让你:不正确。
有谁知道怎么解决这个问题吗?
提前谢谢。
发布于 2015-12-01 15:36:08
一种可能的方式是:
@echo off
:start
set /p test=Write a sentene with the word Mommy Chan in it:
::replaces "Mommy Chan" in %test% to see if it was changed
if "%test:Mommy Chan=%" equ "%test%" goto incorrect
if "%test:Mommy Chan=%" neq "%test%" goto correct
exit /b 0
:correct
echo correct
exit /b 0
:incorrect
echo incorrect
exit /b 0另一个(可能更慢一些,因为它调用了find.exe):
@echo off
:start
set /p test=Write a sentene with the word Mommy Chan in it:
echo %test%|find "Mommy Chan" >nul 2>nul && (
goto :correct
color
)||(
goto incorrect
)
exit /b 0
:correct
echo correct
exit /b 0
:incorrect
echo incorrect
exit /b 0 对于不区分大小写的检查,IF和FIND都使用/I开关。
https://stackoverflow.com/questions/34023792
复制相似问题