打印字符串
@echo off
setlocal enabledelayedexpansion
set str=123456789
echo %str%
pause
截取字符串
获取指定位置字符
rem "获取第m+1个字符"
@echo off
setlocal enabledelayedexpansion
set str=123456789
echo %str:~m,1%
pause
实例
@echo off
setlocal enabledelayedexpansion
set str=123456789
echo %str:~0,1%
echo %str:~2,1%
echo %str:~5,1%
pause
删除最后m个字符
rem "获取第m+1个字符"
@echo off
setlocal enabledelayedexpansion
set str=123456789
echo %str:~0,-m%
pause
实例
@echo off
setlocal enabledelayedexpansion
set str=123456789
echo %str%
echo %str:~0,-4%
echo %str:~0,-2%
echo %str:~0,-6%
pause
截取从n+1开始的m个字符
@echo off
setlocal enabledelayedexpansion
color 0A
set str=123456789
echo %str%
echo %str:~n, m%
pause
实例
@echo off
setlocal enabledelayedexpansion
color 0A
set str=123456789
echo %str%
echo %str:~0,4%
echo %str:~4,2%
echo %str:~1,3%
pause
获取倒数第m个字符
@echo off
setlocal enabledelayedexpansion
color 0A
set str=123456789
echo %str%
echo %str:~-m, 1%
pause
实例
@echo off
setlocal enabledelayedexpansion
color 0A
set str=123456789
echo %str%
echo %str:~-1, 1%
echo %str:~-4, 1%
echo %str:~-6, 1%
pause
获取从倒数第n个字符起,共m个字符
@echo off
setlocal enabledelayedexpansion
color 0A
set str=123456789
echo %str%
echo %str:~-m, n%
pause
实例
@echo off
setlocal enabledelayedexpansion
color 0A
set str=123456789
echo %str%
echo %str:~-8, 4%
echo %str:~-7, 4%
echo %str:~-5, 4%
pause
获取倒数第n个字符后的所有字符
@echo off
setlocal enabledelayedexpansion
color 0A
set str=123456789
echo %str%
echo %str:~-n%
pause
实例
@echo off
setlocal enabledelayedexpansion
color 0A
set str=123456789
echo %str%
echo %str:~-2%
echo %str:~-4%
echo %str:~-6%
pause