Computername variable in cmd
You can do this with substring commands, as per the following transcript:
pax> set xyzzy=KM100-00 KM200-00pax> echo %xyzzy%KM100-00 KM200-00pax> echo %xyzzy:~0,2%KMpax> echo %xyzzy:~-2,2%00pax> if %xyzzy:~0,2%==KM if %xyzzy:~-2,2%==00 echo yesyes
That final (chained) if
statement is the one you're looking for to see if your variable starts with KM
and ends with 00
.
The expression %X:~Y,Z%
will give you the Z
characters starting at position Y
(zero-based) of the variable X
. You can provide a negative value of Y
to make it relative to the end of the string.