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

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

    The solutions that search a file for a substring can also search a string, eg. find or findstr.
    In your case, the easy solution would be to pipe a string into the command instead of supplying a filename eg.

    case-sensitive string:
    echo "abcdefg" | find "bcd"

    ignore case of string:
    echo "abcdefg" | find /I "bcd"

    IF no match found, you will get a blank line response on CMD and %ERRORLEVEL% set to 1

提交回复
热议问题