Batch script If command on a String

batchcmd.exeechostring

What is wrong with the following command lines for my batch script?

set test=BE99012345678901


if %test% == "BE99????????????"(
echo This number begins with BE99
)
Else (
echo This number doesn't begin with BE99
)
pause

Best Answer

Try this:

set test=BE99012345678901

if "%test:~0,4%"=="BE99" (
echo This number begins with BE99
) else (
echo This number doesn't begin with BE99
)
pause

You will get following output:

This number begins with BE99

Kindly note:

if %test% == "BE99????????????" will do this: "BE99012345678901" == "BE99????????????"

and this will show following output:

This number doesn't begin with BE99

Related Question