How can I search backwards through an array? Or are there other ways I can solve this problem?
I have a text array, stored in a field, that is more or less like this:
Satina OG
Yukon Gem OG
Red Maria OG
Desiree OG
Magic Molly
Chieftain
Carola
Without altering the array or using variables, I want to display this array in a Text Display SuperObject so that it looks like this:
ORGANIC
Satina OG
Yukon Gem OG
Red Maria OG
Desiree OG
CONVENTIONAL
Magic Molly
Chieftain
Carola
I can achieve this with the following formula in my SuperObject:
"ORGANIC"+ ¶ + ¶+ arrayrange(MyArray,1,4,¶)+ ¶+ ¶+"CONVENTIONAL" + ¶+ ¶+ arrayrange(MyArray,5,30,¶)
However, the length of the array varies from record to record, so the firstitem
and lastitem
parameters in arrayrange()
can’t be constants. I thought to use arraysearch()
to look for “* OG”, but what I really need to do is find the last occurrence of OG, or rather, to search from the end of the array. So if there were a function called “arraysearchbackwards()
”, my formula would look something like this:
`“ORGANIC”+ ¶ + ¶
- arrayrange(MyArray,1,arraysearchbackwards(MyArray,"* OG",1,¶),¶)
- ¶+“CONVENTIONAL” + ¶+ ¶
- arrayrange(MyArray,arraysearchbackwards(MyArray,"* OG",1,¶)+1,10,¶)`
Since this function only exists in my imagination, can anyone offer an alternative way to achieve this?