<!--- always sort first so the ranges make sense ---> <cfset numbers = listToArray("1,2,3,4,6,7,8,9,10,11,12,15,19,21,22")> <cfset arraySort(numbers, "numeric")> <cfset startAt = 1> <cfset maxPosition = arrayLen(numbers)> <cfset ranges = > <cfloop from="1" to="#maxPosition#" index="pos"> <!--- check difference between current and next number ---> <cfset offset = pos lt maxPosition ? 1 : 0> <cfset gap = numbers[pos+offset] - numbers[pos]> <!--- there was a jump in sequence OR this is the last element ---> <cfif gap gt 1 OR pos eq maxPosition> <cfif startAt lt pos> <!--- range ---> <cfset arrayAppend(ranges, numbers[startAt] &"-"& numbers[pos])> <cfelse> <!--- single value ---> <cfset arrayAppend(ranges, numbers[pos])> </cfif> <cfset startAt = pos + 1> </cfif> </cfloop> List of Ranges: <cfdump var="#arrayToList(ranges, ',')#">
|Help with copying data from all data elements from file2 to file1 based on matching values including additional records in file2 using VB,NET||10||53|
|Help with deleting records by comparing two files using VB.NET||8||56|
|Red error squiggly on vb.net||7||27|
|Application.cfc - what is the order of events?||4||16|
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
25 Experts available now in Live!