Ocean West Posted December 10, 2020 Share Posted December 10, 2020 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 Link to comment Share on other sites More sharing options...
comment Posted December 10, 2020 Share Posted December 10, 2020 I did this a long time ago - way before While() became available: https://www.briandunning.com/cf/734 1 Link to comment Share on other sites More sharing options...
Ocean West Posted December 10, 2020 Author Share Posted December 10, 2020 Much more elegant Link to comment Share on other sites More sharing options...
Recommended Posts
This topic is 1231 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now