This is a strange problem. I have a batch file where I have two arguments. I wish to check the first three characters of each. The first will substring fine, but the second will not. Here is an example:
SET FIRST_ARG=%1
SET SECOND_ARG=%2
ECHO first argument is %FIRST_ARG%
ECHO first substring is %FIRST_ARG :~1,3%
ECHO second argument is %SECOND_ARG%
ECHO second substring is %SECOND_ARG :~1,3%
The first two ECHO statements work fine and display my strings as they should. The ECHO statement “ECHO second argument is” shows the second argument as it should, but the last line that says “ECHO second substring is” returns nothing.
Have I missed something?
Thanks for any help.
Rob
Your issue is the space preceding the colons :. Using
%FIRST_ARG:~1,3%and%SECOND_ARG:~1,3%should fix your issue.