set var=%var:~-1%
zobaczyć SET /?
z wiersza dla docco.
@ECHO OFF
SETLOCAL
SET var=abcd
SET var2=%var:~-1%
CALL :show "-1"
SET var2=%var:~-2%
CALL :show "-2"
SET var2=%var:~-3%
CALL :show "-3"
SET var2=%var:~1%
CALL :show "1"
SET var2=%var:~2%
CALL :show "2"
SET var2=%var:~3%
CALL :show "3"
SET var2=%var:~0,1%
CALL :show "0,1"
SET var2=%var:~0,2%
CALL :show "0,2"
SET var2=%var:~0,3%
CALL :show "0,3"
SET var2=%var:~0,-1%
CALL :show "0,-1"
SET var2=%var:~0,-2%
CALL :show "0,-2"
SET var2=%var:~0,-3%
CALL :show "0,-3"
SET var2=%var:~1,-1%
CALL :show "1,-1"
SET var2=%var:~1,-2%
CALL :show "1,-2"
SET var2=%var:~1,-3%
CALL :show "1,-3"
GOTO :eof
:show
echo Test with "var:~%~1" : var=%var% var2=%var2%
GOTO :eof
Wyniki:
Test with "var:~-1" : var=abcd var2=d
Test with "var:~-2" : var=abcd var2=cd
Test with "var:~-3" : var=abcd var2=bcd
Test with "var:~1" : var=abcd var2=bcd
Test with "var:~2" : var=abcd var2=cd
Test with "var:~3" : var=abcd var2=d
Test with "var:~0,1" : var=abcd var2=a
Test with "var:~0,2" : var=abcd var2=ab
Test with "var:~0,3" : var=abcd var2=abc
Test with "var:~0,-1" : var=abcd var2=abc
Test with "var:~0,-2" : var=abcd var2=ab
Test with "var:~0,-3" : var=abcd var2=a
Test with "var:~1,-1" : var=abcd var2=bc
Test with "var:~1,-2" : var=abcd var2=b
Test with "var:~1,-3" : var=abcd var2=
Na wyciągu IF
, spróbuj
IF "%var:~-1%"=="0" (dosomething) else (dosomethingelse)
po pomoc, wpisz 'help set'. – Endoro