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

前端 未结 10 2247
深忆病人
深忆病人 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:46

    I usually do something like this:

    Echo.%1 | findstr /C:"%2">nul && (
        REM TRUE
    ) || (
        REM FALSE
    )
    

    Example:

    Echo.Hello world | findstr /C:"world">nul && (
        Echo.TRUE
    ) || (
        Echo.FALSE
    )
    
    Echo.Hello world | findstr /C:"World">nul && (Echo.TRUE) || (Echo.FALSE)
    

    Output:

    TRUE
    FALSE
    

    I don't know if this is the best way.

提交回复
热议问题