Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 批处理文件:查找子字符串是否在字符串中(不在文件中)第2部分-使用变量_String_Batch File_Substring_Batch Processing_Findstr - Fatal编程技术网

String 批处理文件:查找子字符串是否在字符串中(不在文件中)第2部分-使用变量

String 批处理文件:查找子字符串是否在字符串中(不在文件中)第2部分-使用变量,string,batch-file,substring,batch-processing,findstr,String,Batch File,Substring,Batch Processing,Findstr,在Windows批处理文件中,我有一个字符串“abcdefg”。我想检查字符串中是否有“bcd”,但我也希望每个bcd都在一个变量中,或者为字符串传入一个参数 这个解决方案很接近,但使用常量而不是变量。 解决方案是使用FindStr和NULL重定向>nul 另存为test.bat并使用要搜索的参数执行,如下所示:test Tomcat7 解决方案是使用FindStr和NULL重定向>nul 另存为test.bat并使用要搜索的参数执行,如下所示:test Tomcat7 试试看: set "va

在Windows批处理文件中,我有一个字符串“abcdefg”。我想检查字符串中是否有“bcd”,但我也希望每个bcd都在一个变量中,或者为字符串传入一个参数

这个解决方案很接近,但使用常量而不是变量。

解决方案是使用FindStr和NULL重定向>nul

另存为test.bat并使用要搜索的参数执行,如下所示:test Tomcat7

解决方案是使用FindStr和NULL重定向>nul

另存为test.bat并使用要搜索的参数执行,如下所示:test Tomcat7

试试看:

set "var=abcdefg"
set "search=bcd"
CALL set "test=%%var:%search%=%%"
if "%test%"=="%var%" (echo %search% is not in %var%) else echo %search% in %var% found
试试看:

set "var=abcdefg"
set "search=bcd"
CALL set "test=%%var:%search%=%%"
if "%test%"=="%var%" (echo %search% is not in %var%) else echo %search% in %var% found

这里的第二个答案帮助了我,我在字符串中有方括号,并设法用这个答案解决问题。这里的第二个答案帮助了我,我在字符串中有方括号,并设法用这个答案解决问题。
set "var=abcdefg"
set "search=bcd"
CALL set "test=%%var:%search%=%%"
if "%test%"=="%var%" (echo %search% is not in %var%) else echo %search% in %var% found
set "var=abcdefg"
set "search=bcd"
echo %var%|findstr /lic:"%search%" >nul && echo %search% found || echo %search% not found