December 10, 20205 yr Someone requested on face book a function to find a gap in sequence. Quote I have a list of numbers such as 1¶2¶3¶6¶7¶8¶12¶13 I need to be able create a text string from this which looks like 1-3, 6-8, 12-13 This is my attempt for that with a While Function If I were to add this to a custom function i would Replace X with a parameter - also perhaps suggest to do a unique list and sort list on the parameter. While ( [ x = "1¶2¶3¶6¶7¶8¶12¶13¶16¶17¶18" ; y = "" ; z = "" ; out = "" ; i = 1 ; c = ValueCount ( x ) ] ; i ≤ c ; [ y = GetValue ( x ; i ) ; z = case ( y+1 = GetValue ( x ; i+1 ) or y-1 = GetValue ( x ; i+1 ) ; "" ; "-" & y & "," ) ; out = Case ( i = 1 ; y ; Right (out ;1) = "," ; out & y ; out & z ) ; i = i+1 ] ; Case( right (out;1) = "," ; Left ( out ; Length (out) -1 )) ) i haven't fully tested so please test it out before use in production - if you see room for improvement it is welcomed
December 10, 20205 yr I did this a long time ago - way before While() became available: https://www.briandunning.com/cf/734
Create an account or sign in to comment