BAT批处理,如何判断变量中,是否包含了指定的字符串?

2025-01-08 01:32:32
推荐回答(2个)
回答1:

@echo off
set "变量1=abcdefghijklmnopq"
set 返回代码=
echo %变量1%|findstr /c:"abc">nul 2>nul&&set 返回代码=true||set 返回代码=false

回答2:

@echo off & SET 变量1="ABCDEFG"
echo %变量1%|find /i "CD">nul 2>nul&&echo TURE||echo FALSE
pause>nul