How to remove item that contains @ from iEnumerable?

Hello guys,

I am trying to remove items from a iEnumerable according to specific criteria (i.e. remove items that contains “@” in the iEnumerable variable TextList).

What activities or string manipulation can help to do that? Thank you.

@boxli,

Use this LINQ to remove items contains “@”

Textlist= Textlist.Where(Function(item) Not item.Contains("@"))
1 Like

Unfortunately we cannot refer to the validation issue.

However, the nature of an IEnumarable is about returning its elements and is the base ground for other more specialized datatypes. Those data types are designed to offer additional functionalities.

give a try at:

  • reconstruncting the testList by filtering
    • Assign Activity:
      • Textlist = Testlist.Where(Function (x) Not x.Contains(“@”))

feel free to materialize it into another Datatype e.g. list with appending toList()

Keep in mind: IEnumerable are deferred executed

For entering more the topic LINQ (which was used) have a look here:
[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum

For Each item In TextList → If Not item.Contains(“@”) Then add to new list

Thanks, but it seems that there is an error.

dont use an already existing variable within the function definition. have a look here:

we used x

Hi @boxli,
Try below
Textlist.Where(Function(currentText) Not currentText.Contains("@")).ToArray()

Regards,
Arivu

UPD1 - second validation issue
We assume that the reeving variable datatype is as string array. As mentioned

which can also be done for arrays with toArray

will change to

extlist = Testlist.Where(Function (x) Not x.Contains("@")).toArray

Kindly note: as far we can refer to your above modelling keep in mind that we cannot change a collection / IEnumerable which is looped on. So besides on any compilation issues also the flow:

  • loop over collection
    • check loop item
      • remove loop item from looped collection

will result to an runtime error

Well, the problem is that (as seen from the screenshot) @boxli wants perform some action with the value (specifically assing) before removing it from iEnumerable.

So in order to use LINQ “to remove item that contains @ from iEnumerable?” he would need to completely redesign the workflow.

Cheers

@boxli The error happens because currentText conflicts with an existing variable, and the return type is incorrect. Try renaming the lambda parameter and explicitly converting the result to a list like this:
TextList = TextList.Where(Function(txt) Not txt.Contains("@")).ToList()

For Eg:
Consider a var of DataType IEnumerable
Textlist = {“Apple@”, “Banana”, “Cherry”}

If you want to get only the items which don’t have ‘@’ in it.

Use an Assign actvity:
If need to store the results in the same variable
To: Textlist ; Value : Textlist.Where(Function(x) Not x.Contains(“@”))

If need to get the result in new var type
Create another var of same var type IEnumerable
To: NewVariable ; Value : Textlist.Where(Function(x) Not x.Contains(“@”))

Result is {“Banana”, “Cherry”}

@boxli

Try below xmal file it may help you better.
Testing.zip (1.4 KB)

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