ehart12
asked on
Build a Number Range
Hi Experts,
I have been unable to do this and hoping somebody can help! I have the following string of comma delimited numbers and that I need to breakdown and display as a range.
String: 1,2,3,4,6,7,8,9,10,11,12,1 5,19,21,22
Display as: 1-4, 6-12, 15, 19, 21-22
Any help would be greatly appreciated,
Eric
I have been unable to do this and hoping somebody can help! I have the following string of comma delimited numbers and that I need to breakdown and display as a range.
String: 1,2,3,4,6,7,8,9,10,11,12,1
Display as: 1-4, 6-12, 15, 19, 21-22
Any help would be greatly appreciated,
Eric
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It's probably simplest to do it before adding the values to the array. Totally untested, but something along these lines
...
<cfif startAt lt pos>
<!--- range --->
<cfset fromValue = NumberFormat( numbers[startAt] , "000")>
<cfset toValue = NumberFormat( numbers[pos] , "000")>
<cfset arrayAppend(ranges, fromValue &"-"& toValue )>
<cfelse>
<!--- single value --->
<cfset arrayAppend(ranges, NumberFormat(numbers[pos], "000"))>
</cfif>
...
<cfif startAt lt pos>
<!--- range --->
<cfset fromValue = NumberFormat( numbers[startAt] , "000")>
<cfset toValue = NumberFormat( numbers[pos] , "000")>
<cfset arrayAppend(ranges, fromValue &"-"& toValue )>
<cfelse>
<!--- single value --->
<cfset arrayAppend(ranges, NumberFormat(numbers[pos],
</cfif>
ASKER
Excellent, thank you!
ASKER
Once again, thank you the above solution! What would be the best way to apply some type of numberformat so the actual format is as follows (three places with leading 0 to fill);
Is: 1-4, 6-12, 15, 19, 21-22
Desired: 001-004, 006-012, 015, 019, 021-022
Thank you,
Eric