Batch file: Find if substring is in string (not in a file)

前端 未结 10 2237
深忆病人
深忆病人 2020-11-22 14:14

In a batch file, I have a string abcdefg. I want to check if bcd is in the string.

Unfortunately it seems all of the solutions I\'m find

10条回答
  •  自闭症患者
    2020-11-22 14:48

    To find a text in the Var, Example:

    var_text="demo string test"
    Echo.%var_text% | findstr /C:"test">nul && (
        echo "found test" 
        ) || Echo.%var_text% | findstr /C:"String">nul && (
                 echo "found String with S uppercase letter" 
        ) || (
                 echo "Not Found " 
        )
    

    LEGEND:

    1. & Execute_that AND execute_this
    2. || Ex: Execute_that IF_FAIL execute this
    3. && Ex: Execute_that IF_SUCCESSFUL execute this
    4. >nul no echo result of command
    5. findstr
    6. /C: Use string as a literal search string

提交回复
热议问题