Add array item to new array

Hello,

I am looping through an array of strings. If the item contains a specific text, I need to add the item to a new array. How would I do this? Any help is appreciated.

Thanks in advance!

Hi @william.coulson

U can do the following way

Initislse a list list_1= New List (Of String)

  1. Use for each loop to loop through array

Inside it use an if Condition with condition as

item.Contains(specific text),

If it is true

Then use add to collections activitiy for adding item to list_1

After adding required items to collections

At the exit, use

list_1.ToArray to convert list to array

As u can’t add items to array so add items to list and convert list to array, this is the overall logic applied here.

Hope it helps you

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed:

3 Likes

Hi @NIVED_NAMBIAR,

Is this the correct variable type for the list?

1 Like

Yes buddy

1 Like

You can create a variable of type list of strings
and within the loop after the condition just use add to collection activity to add that item to the list

1 Like

Another possible solution is to use Linq:

newArray = oldArray.Where(Function(x) x.Contains("batman")).ToArray
3 Likes

Hi @NIVED_NAMBIAR,

Thank you, your solution works great. The only issue I now face is the timing, as I am filtering through 74,000+ items. Thanks for your help!

Thank you everyone for your time and your responses!

1 Like

Hi @william.coulson

If timing is the issue

Then try with linq query as provided by @ptrobot

It works well too

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.