Give this one a go:
@echo off
set "appdir=This is testing for substring : Management\s18vx"
echo %appdir%
REM get substring i.e, s18vx
Set "SubStr=%appdir:~43%"
echo %SubStr%
pause
The Spaces before and after =
is really not wanted it here. This will create a variable name with a trialing space and a value with a leading space, i.e: set variable = value
will therefore become %variable %
and value
.
Also wrap your variables in double quotes to eliminate additional whitespace, especially after the variable string.
For more help on the set
command, open cmd.exe
and type set /?
Some side notes:
Echo is on by default, unless this forms part of a script where echo is turned off earlier and you want to turn it on for some reason, you do not need to switch it on.
Also, I suggest if you want an end result only to turn @echo off
because echo on
is almost like a debug function, it echo
s each of the commands you run, where echo off
will disable this and display the end result only.