Tinderbox Forum

Select a range of values from a list/set

I trying to figure out a way to select a range of values from a list/set.

I am looking for something like…

Pseudo-code
$MyList=$Text.split("#").at(1…9)

In my example I would like to remove the first occurrence (set/list.at(0)) in the list. Remove doesn’t work as the value of the first occurrence can be any string of any length

Thanks for your support.

There are a few ways to do this. If you’re looking to remove data, you could apply the following stamp, or run an agent. Start with the stamp to make sure it is working properly and then you can run the agent.

$MyList=$MyList.replace(“VALUE”,"");

For example=$MyList.replace(“Brussels sprouts”,"");

This will replace Brussels sprouts with nothing, i.e. remove it. It does not matter where in the list the item is.

Now, if the value is in the list multiple times and you only want to replace the first instance, I’m not sure. Need to think about this.

There are some good starts in the last answer. Could you provide a sample list that illustrates the actual problem. There are lots of edge cases here - such as at the end of @satikusala’s post. these may or may not reflect your problem. With a ‘test list’ we can zero in on the problem and scope it better.

These two statements are at odds. One wants a range, the other a precise item.

For a range, you could use .each() with an iteration counter, but the real task is insufficiently defined to give a useful answer.

Thanks Michael and Mark for your reply.

$MyList =“Proven, a rating of knowledge based on corroboration
Proven refers to an understanding that has been shown to be correct enough times to enough people to hold it as fact.;Authenticating;Authenticating a Particular Group;Being an Authentic Group;Being Authentic;Being Verifiable by Someone;Confirming with Proof;Corroborating”

I would like to delete the first entry of the list (everything what comes before the first occurrence of “;”). As I would like to have a stamp for this I cannot use “remove” as I cannot hardcode the content of the first entry/string.

1 Like

This should work:

$MyList=$MyList.replace(“Proven, a rating of knowledge based on corroboration
Proven refers to an understanding that has been shown to be correct enough times to enough people to hold it as fact.”,"");

Is there a way to make the make the replace generic - by using a variable? I have a long list of notes where I would like to apply a stamp and replace the first item. On runtime I don’t know what the first string in the list might be. The string could anything and of any length.

How about this:

$MyList=$MyList-$MyList.at(0)
1 Like

Does this not assume that this item is always the first item in the list? What if it is not?

The request was:

This is literally

$MyList=$MyList-$MyList.at(0)
1 Like

There are two sorts of multi-value attribute types" List and Set. Lists allow dupes and do not, of themselves alters their sort order—though Action code offers means to do so deliberately. Sets de-dupe and generally retain their last used order but if in doubt, pass the data to a list before work.

Thus @eastgate’s solution works. ay() is zero-based so .at(0) is the first item in the list. Here,

$MyList=$MyList-$MyList.at(0);

might be more easily understood as:

$MyString=$MyList.at(0);
$MyList=$MyList-$MyString;

but happily, Tinderbox lets us do all that in one operation. So in either method above, if $MyList is “and:bee;cow” the result is “bee;cow” as “ant” is the first list item (.at(0)) of the list at the start of the process.

1 Like

Thanks, that’s really cool and works great for my purpose!

$MyList=$MyList-$MyList.at(0)