我想判斷輸入段是否有效,並且有一個有效字符串列表(說「aaa」,「bbb」,「ccc」,「ddd」是正確的),但我不喜歡使用if-else。我想要一個簡單的方法來做到這一點。 我喜歡的東西,如:windows批處理文件中的字符串循環
set env=%1
for %%A in ("aaa" "bbb" "ccc" "ddd") do if "%env%"==%%A echo true else goto end
我不知道該怎麼做了這一點。
我想是這樣的:
set env=%1
if "%env%"neq"aaa" and "%env%"neq"bbb" and "%env%"neq"ccc"and "%env%"neq"ddd" (
goto end
)
感謝aschipfl和脫線。
我的決心是:
for %%a in (aaa bbb ccc ddd) do (
if "%env%"=="%%a" (
goto next
)
)
@echo Wrong parameter!
goto end
:next
[如何查找字符串是否在DOS批處理文件中的字符串列表]中可能的重複(http://stackoverflow.com/questions/11235153/how-to-find-if-a-string-是-IN-A-列表的串-IN-A-DOS的批處理文件) –