You can do this using substring commands, according to the following decoding:
pax> set xyzzy=KM100-00 KM200-00 pax> echo %xyzzy% KM100-00 KM200-00 pax> echo %xyzzy:~0,2% KM pax> echo %xyzzy:~-2,2% 00 pax> if %xyzzy:~0,2%==KM if %xyzzy:~-2,2%==00 echo yes yes
This final (chained) if is the one you are looking to see if your variable starts with KM and ends at 00 .
The expression %X:~Y,Z% will give you the characters Z , starting at position Y (with zero base) of the variable X You can specify a negative Y value to make it relative to the end of the line.
source share