Dermot
Board Regular
- Joined
- Aug 11, 2006
- Messages
- 199
- Office Version
- 365
- Platform
- Windows
SPLITTER splits a text string into pieces based on a delimiter, using a recursive lambda
It is not as brief as SPLITONDELIMITER, but is an example of recursion, and in particular, shows how to store an increasing list of items from one recursion to the next.
Specifically, this
will take an existing list L of length n and append a new item T on the end, so the array now has n+1 items.
This could be very useful in recursive lambdas which need to store variable length lists.
It starts by finding the next delimiter position (set to 0 if absent), and initialises the list of split items if missing.
Then if there is a delimiter, it calls splitter again, passing the string (minus the first item) and the array of items (adding the one just found)
If there is no delimiter left, it adds the last piece of text to the list and returns it as a row of items
It is not as brief as SPLITONDELIMITER, but is an example of recursion, and in particular, shows how to store an increasing list of items from one recursion to the next.
Specifically, this
Excel Formula:
IF(SEQUENCE(1,n+1)<n+1, L, T)
This could be very useful in recursive lambdas which need to store variable length lists.
Excel Formula:
=LAMBDA(txt,delim,[n],[list],
LET(p,IFERROR(FIND(delim,txt),0), list,IF(ISOMITTED(list), {""}, list),
IF(p,SPLITTER(MID(txt,p+1,99),delim,n+1, IF(SEQUENCE(1,n+1)<n+1,list,LEFT(txt,p-1))),
IF(n=0,txt,IF(SEQUENCE(1,n+1)<n+1,list,txt)))))
It starts by finding the next delimiter position (set to 0 if absent), and initialises the list of split items if missing.
Then if there is a delimiter, it calls splitter again, passing the string (minus the first item) and the array of items (adding the one just found)
If there is no delimiter left, it adds the last piece of text to the list and returns it as a row of items
Upvote
0