请高手帮忙:
如原始数据data.txt:
1
2
5
7
8
9
10
要求结果显示为:
1-2,5-5,7-10
请高手解决一下,非常感谢。
如原始数据data.txt:
1
2
5
7
8
9
10
要求结果显示为:
1-2,5-5,7-10
请高手解决一下,非常感谢。
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

@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