如何使用批处理查看字符串是否包含子字符串 [英] How to see if a string contains a substring using batch
问题描述
当前试图查看字符串(在本例中为文本文件的当前行)是否包含子字符串#
.我是新手,所以我不确定我将如何做这样的事情.这是代码 set substring =#
Currently trying to see if a string, in this case the current line of a text file, contains a substring #
. I am new to batch, so I am not sure exactly how I would do something like this. Here is the code
set substring = #
for /f "delims=," %%a in (Text.txt) do (
set string = %%a
//check substring method
echo %string%
)
推荐答案
echo %%a|find "substring" >nul
if errorlevel 1 (echo notfound) else (echo found)
批处理对 SET
语句中的空格敏感. SET FLAG = N
将名为"FLAG Space "的变量设置为" Space N"
Batch is sensitive to spaces in a SET
statement. SET FLAG = N
sets a variable named "FLAGSpace" to a value of "SpaceN"
语法 SET"var = value"
(值可能为空)用于确保分配的值中不包含任何杂散尾随空格. set/a
可以安全地无引号"使用.
The syntax SET "var=value"
(where value may be empty) is used to ensure that any stray trailing spaces are NOT included in the value assigned. set /a
can safely be used "quoteless".
这篇关于如何使用批处理查看字符串是否包含子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!