復(fù)制代碼 代碼如下:
::code by lxmxn @ cn-dos.net .
::目的:幫助新手們更好的理解變量字符截取功能.
::Date 2006-12-16 .
::說明:有的變量截取之后值為空,這是正常的.
::
@echo offsetlocal EnableDelayedexpansion
::設(shè)置變量var的值:
set var=0123456789ABCDEF
call :begin
for /l %%a in (1,3,15) do (
for /l %%b in (1,4,15) do (
call :printf %%a %%b
)
)
call :begin
for /l %%a in (1,4,15) do (
for /l %%b in (-1,-3,-15) do (
call :printf %%a %%b
)
)
call :begin
for /l %%a in (-2,-3,-15) do (
for /l %%b in (1,4,15) do (
call :printf %%a %%b
)
)
call :begin
for /l %%a in (-1,-4,-15) do (
for /l %%b in (-2,-3,-15) do (
call :printf %%a %%b
)
)
pause
endlocalclsecho.
echo 演示結(jié)束了,任意鍵退出……
pause>nul
goto :eof
::輸出結(jié)果:
:printf
echo %%var:~%1,%2%% 截取之后的字符為: !var:~%1,%2!
goto :eof
::清理屏幕:
:begin
echo\pauseclsecho.
echo 變量var的值為: %var%
echo.
goto :eof
您可能感興趣的文章:- 分享dos批處理命令的一些使用技巧(截取字符串)
- 批處理BAT替換與截取字符串的用法t1=%a:~3%是什么意思
- DOS截取字符串的方法