Get Position of Array Item

Hello -

I have a very basic question that has likely been answered before, but I’ve been unable to find an answer on this forum. Apologies if it has been asked.

I’m looping through an array and want to leave out a specific item in the array. My approach right now is a For Each loop with an If activity that asks if the item is the first position in the array. I can’t get the right syntax for this if condition, though.

Any help is appreciated!

1 Like

Hello @bdale04,

could you please attach your xaml file and give us array?

Thanks,
Pankaj

@Pankaj.Patil

Here is an example.

The if condition is a placeholder for now as it could ignore any array item that is equal to array(0). Whereas I want it to only skip array(0) and not any potential array that happen to be equal to array(0).

What I want is for the array to be converted to a string that skips the first array item. In this case, “One”. So it will result in “TwoThreeFour” and not “OneTwoThreeFour”.

ArrayPosition.xaml (6.9 KB)

Hello @bdale04,

I downloaded and saw your code. I guess that it’s correct what you’re expecting.
you want to skip first element of array. have a look at below result,

MoveDownloadFile execution started
TwoThreeFour
MoveDownloadFile execution ended in: 00:00:08

Thanks,
Pankaj

Hi Pankaj,

The code I provided does not do what I want it to. I want it to skip the first position of an array, not any array item that is equal to the first array.

Imagine Array = {“One”, “Two”, “Three”, “Four”, “One”}. The code right now would result in “TwoThreeFour”. I want it to be “TwoThreeFourOne”.

@bdale04 my recommendation its always to use linq libraries. you can search around internet but for example:
if you just write yourArray.ToList().Skip(1) (you will skip the first item) you can also do a lot of different things like order/filter/take some items only …

in the case you want to also join the string you can do string.join(“,”,yourArray.ToList().Skip(1)) and this would give you ur exact answer

try a message box with this and it will works :slight_smile:

string.join(“,”,yourArray.ToList().Skip(1))

1 Like

Yes go with @Ignacio_Insua_Feito’s suggestion

yourarray.Skip(1) //will return the array missing the first item

When you compare a string to the item, it will match multiple items if there are duplicates, so that approach won’t work. But if you simply skip the first item, that will work.

You can also check the index of the array in a loop by doing this:

ForEach item In yourarray
    If Array.IndexOf(yourarray, item) = 0

But, sounds like using .Skip() would be best approach in my opinion.

EDIT: also let me add that you can use the .Skip in your ForEach too to loop through all items minus the first item

ForEach item In yourarray.Skip(1)

Regards.

3 Likes