如何检查字符串是否包含批处理中的子字符串 这里有一个以相同标题问的问题,但我不明白它在说什么。 我要做的就是查看最终用户是否正在有限地放入相同的文本。这会Al ...

问题描述 投票:0回答:1
图像捕获progam运行(菜单的示例)

所有我都在尝试查看名为%scamble%

的字符串是否包含

"Yes"

"Y""No"

"N"

,而无需使用大量的if语句。再次,我不知道我在做什么...我学到了这一切。所以把我当作一个好奇的菜鸟。
类似
echo This is a ONE TIME prompt (for this session ONLY).
set /p scramble=Y/N: || set scramble=Y
for /f "text=," %%a in (%scamble%) do (
    set string = %%a
    if "!string:%substring%=!"=="!string!" (
        echo Found!
    )
)
我必须重申,我不知道自己在做什么,但是我认为我可能会有些了解。所以我问你,互联网的人,请帮忙!谢谢
	
the以前的问题答案:
if not x%str1:bcd=%==x%str1% echo It contains bcd
除非召集:

@echo off SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS set str1=abcdefg if "%~1" == "" Call :CheckString pause exit :CheckString if not x%str1:bcd=%==x%str1% echo It contains bcd exit /b

您仍然需要其中4个,所以没有太大的区别,否则可以方便。
If "%%a" == "Y" (echo Is Y) ELSE (echo Not Y)

theles还与琴弦相呼应:

string if-statement batch-file cmd substring
1个回答
0
投票

以个人的方式我只会使用一个选择CMD:

:: Numbers:
echo Press 1 for blah
echo Press 2 for blah
choice /n /c 12
if "%errorlevel%" == "1" (
    echo Do whatever for 1...
    )
if "%errorlevel%" == "2" (
    echo Do whatever for 2...
    )
pause
exit

:: Even better Using Numbers:
echo Press 1 for blah
echo Press 2 for blah
choice /n /c 12
:: Loop from 1, up by 1 at a time, upto 5..
For /L %%i in (1,1,5) Do (
    If "%errorlevel%" EQU "%%i" (echo Number %%i: This was Selected by User)
    )
pause
exit

:: Letters: echo Press 1 for blah echo Press 2 for blah choice /n /c 12 if "%errorlevel%" == "1" ( echo Do whatever for 1... ) if "%errorlevel%" == "2" ( echo Do whatever for 2... ) pause exit

Hope它有帮助:)
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.