确实,
这个错字不能忽略,youxi 复制下面的改一下!
::- @echo off&color 1f&rem num=15 nums=30
- mode con: cols=80 lines=35
- set "var=1234567890"
- set "num= "
- set "nums= "
- rem 第一屏 舍弃
- cls&echo 第一屏 舍弃
- echo\&echo %num% var=%var%&echo\
- for /l %%i in (1 1 3) do call :dan %%i
- echo\
- for /l %%i in (0 1 1) do call :yi %%i
- echo\
- for /l %%i in (0 1 2) do call :_yi %%i
- echo ~ 波浪号后面的数字:为正数表示舍弃变量的前位;
- echo , 逗号后面的数字为正数表示取变量的舍弃以后的前几位;
- echo , 逗号后面为负数表示舍弃变量的后几位
- echo\&echo\&pause&color 1e
- rem 第二屏 取
- cls&echo 第二屏 取
- echo\&echo %num% var=%var%&echo\
- for /l %%i in (-1 -1 -3) do call :dan %%i
- echo\
- for /l %%i in (-4 -1 -6) do call :er %%i
- echo\
- call :_er -8
- echo ~ 波浪号后面直接跟负数表示取变量的后几位
- echo , 逗号后面的数字为正数表示取变量的舍弃以后的前几位;
- echo , 逗号后面为负数表示舍弃变量的后几位
- echo\&echo\&pause&color 1f
- rem 第三屏 替换 删除
- cls&echo 第三屏 替换 删除
- set "var=abc:\123\ef:g\123\456"hij"789"klm\"
- echo\&echo %num%var=%var%
- echo\
- call :san
- echo = 号左边为要替换掉的字符, 右边为需替换来的字符
- echo = 号左边要替换掉的字符前面加个*号,代表第一次出现的字符及其前面的所有字符
- echo\
- echo ========= 演示完毕 ========= 按任意键退出 ==========
- pause>nul
- exit
-
- :dan
- set shu=%1
- if %shu% lss 0 (set aa=取&set ji=最后) else set aa=舍弃&set ji=前
- if "%shu:~0,1%"=="-" set shu=%shu:~1%
- set str1=%%var:~%1%%%num%
- set str2=%aa%var的%ji%%shu%位%nums%
- call set str3=%%var:~%1%%%num%
- call echo %%str1:~0,15%% %%str2:~0,30%% %%str3:~0,15%%
- goto :eof
- :yi
- set shu=%1
- if %shu% lss 0 (set aa=取&set ji=最后) else set aa=舍弃&set ji=前
- for /l %%i in (1 1 3) do (
- set str1=%%var:~%1,%%i%%%num%
- set str2=%aa%var的%ji%%shu%位之后取%%i位%nums%
- call set str3=%%var:~%1,%%i%%%num%
- call echo %%str1:~0,15%% %%str2:~0,26%% %%str3:~0,15%%
- if %%i==3 echo\
- )
- goto :eof
- :_yi
- for /l %%i in (-1 -1 -3) do (
- set str1=%%var:~%1,%%i%%%num%
- set str2=舍弃var的前%1位和%%i位%nums%
- call set str3=%%var:~%1,%%i%%%num%
- call echo %%str1:~0,15%% %%str2:~0,28%% %%str3:~0,15%%
- if %%i==-3 echo\
- )
- goto :eof
- :er
- set sss=%1
- set sss=%sss:~1%
- for /l %%i in (1 1 3) do (
- set str1=%%var:~%1,%%i%%%num%
- set str2=从var的倒数%sss%位开始取%%i位%nums%
- call set str3=%%var:~%1,%%i%%%num%
- call echo %%str1:~0,15%% %%str2:~0,24%% %%str3:~0,15%%
- if %%i==3 echo\
- )
- goto :eof
- :_er
- set sss=%1
- set sss=%sss:~1%
- for /l %%i in (-1 -1 -3) do (
- set str1=%%var:~%1,%%i%%%num%
- set str2=从var的倒数%sss%位开始并舍弃最后%%i位%nums%
- call set str3=%%var:~%1,%%i%%%num%
- call echo %%str1:~0,15%% %%str2:~0,20%% %%str3:~0,15%%
- if %%i==-3 echo\
- )
- goto :eof
- :san
- set str1=%%var:"=%%%num%
- set str2=删除var中的所有^"号%num%
- set str3=%var:"=%%nums%
- call echo %%str1:~0,13%% %%str2:~0,23%% %%str3:~0,30%%
- set str1=%%var:\=%%%num%
- set str2=删除var中的所有\号%num%
- set str3=%var:\=%%nums%
- call echo %%str1:~0,13%% %%str2:~0,23%% %%str3:~0,30%%
- set str1=%%var::=%%%num%
- set str2=删除var中的所有:号%num%
- set str3=%var::=%%nums%
- call echo %%str1:~0,13%% %%str2:~0,23%% %%str3:~0,30%%
- echo\
- set str1=%%var:"=好%%%num%
- set str2=替换var中的所有^"号为好字%num%
- set str3=%var:"=好%%nums%
- call echo %%str1:~0,12%% %%str2:~0,20%% %%str3:~0,30%%
- set str1=%%var:\=好%%%num%
- set str2=替换var中的所有\号为好字%num%
- set str3=%var:\=好%%nums%
- call echo %%str1:~0,12%% %%str2:~0,20%% %%str3:~0,30%%
- set str1=%%var::=好%%%num%
- set str2=替换var中的所有:号为好字%num%
- set str3=%var::=好%%nums%
- call echo %%str1:~0,12%% %%str2:~0,20%% %%str3:~0,30%%
- echo\
- set str1=%%var:*"=%%%num%
- set str3=%var:*"=%%nums%
- echo 删除var中的第一次出现的^"号及其前面的所有字符
- call echo %%str1:~0,15%% %%str3:~0,30%%
- echo.
- set str1=%%var:*\=%%%num%
- set str3=%var:*\=%%nums%
- echo 删除var中的第一次出现的\号及其前面的所有字符
- call echo %%str1:~0,15%% %%str3:~0,30%%
- echo.
- set str1=%%var:*:=%%%num%
- set str3=%var:*:=%%nums%
- echo 删除var中的第一次出现的:号及其前面的所有字符
- call echo %%str1:~0,15%% %%str3:~0,30%%
- echo\
- set str1=%%var:*"=ppp%%%num%
- set str3=%var:*"=ppp%%nums%
- echo 替换var中的第一次出现的^"号及其前面的所有字符为ppp
- call echo %%str1:~0,15%% %%str3:~0,30%%
- echo.
- set str1=%%var:*\=ppp%%%num%
- set str3=%var:*\=ppp%%nums%
- echo 替换var中的第一次出现的\号及其前面的所有字符为ppp
- call echo %%str1:~0,15%% %%str3:~0,30%%
- echo.
- set str1=%%var:*:=ppp%%%num%
- set str3=%var:*:=ppp%%nums%
- echo 替换var中的第一次出现的:号及其前面的所有字符为ppp
- call echo %%str1:~0,15%% %%str3:~0,30%%
- echo\
- goto :eof
复制代码
|