在批处理文件中,我有一个字符串
不幸的是,似乎我找到的所有解决方案都是在文件中搜索子字符串,而不是在字符串中搜索子字符串。
是否有简便的方法来解决这个问题?
abcdefg
。 我想检查字符串中是否存在bcd
。不幸的是,似乎我找到的所有解决方案都是在文件中搜索子字符串,而不是在字符串中搜索子字符串。
是否有简便的方法来解决这个问题?
abcdefg
。 我想检查字符串中是否存在bcd
。在@user839791的回答基础上,我添加了一些内容。
@echo off
rem --Set variable below--
set var=condition
rem --Uncomment below line to display contents of variable--
::echo The variable is %var%
rem --Change condition to desired string below--
ECHO.%var%| FIND /I "condition">Nul && (
rem --Occurs if the string is found--
Echo.Variable is "condition"
color C
pause
) || (
rem --Occurs if the string isn't found--
Echo.Variable is not "condition"
color A
pause
)
是的,我们可以在字符串中找到子字符串:
echo.%data% | FINDSTR /I "POS">Nul && (SET var=POS) || (SET noVar="variable not found")
echo.%data% | FINDSTR /I "TD1">Nul && (SET var=TD1) || (SET noVar="variable not found")
GOTO %var%
:POS
echo processes inside POS
GOTO END
:TD1
echo processes inside TD1
:END