标题: 如何判断数据的连续性并分段显示出来
[打印本页]
作者: zhengdan
时间: 2009-11-24 09:38
标题: 如何判断数据的连续性并分段显示出来
请高手帮忙:
如原始数据data.txt:
1
2
5
7
8
9
10
要求结果显示为:
1-2,5-5,7-10
请高手解决一下,非常感谢。
作者: zhengdan
时间: 2009-11-24 11:48
请大家帮忙一下,需要这段代码,

作者: moniuming
时间: 2009-11-25 11:33
这样???
@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