这样???
@echo off
setlocal enabledelayedexpansion
set "str=1 2 5 7 8 9 10 15 16 17 20 22"
::计算这个序列的个数
for %%a in (%str%) do (set /a countAll+=1)
::获取第一个数字
for /f %%a in ("%str%") do (
set "num1=%%a"
)
set /a num2=num1-1
for %%a in (%str%) do (
set /a num2+=1,countTest+=1
if not "!num2!"=="%%a" (
set /a num2-=1
echo.!num1!-!num2!
set /a num1=%%a,num2=%%a
)
if "!countTest!"=="!countAll!" (
echo.!num1!-!num2!
)
)
pause