question

kvin93-1864 avatar image
0 Votes"
kvin93-1864 asked Viorel-1 edited

Need help on Enumerable.Where

Greetings.

I have 2 long strings (containing some codes that are separated with commas like : a1,r4,gt, ...), and I want to make a comparison among them as described below , along with doing a clean up in the second string at the end (described below) :


I first need to split strings to remove commas and to only have codes as items of a collection. SO :

 Dim t1 as String = "a1,gr4,bs4,y7,d3"
 Dim t2 as String = "h8,gr4,op4,y7,d3"

 Dim ar1 As String() = Split(t1, ",")
 Dim ar2 As String() = Split(t2, ",")

  • I may actually have around 10,000 items in ar1 or ar2 after doing the splitting above. That's what I meant by long strings.

I now want to check if any item in collection of ar1 is in collection of ar2, so one of the fastest ways I've found is :

         Dim strFull As IEnumerable(Of String) = ar1.Intersect(ar2)

Now that I know what items are in common between ar1 and ar2 (collection of strFull) , I need to clean ar2 from strFull items. It means that there should be no trace of strFull items in ar2 collection at the end.

How can I do that ? I wanted to use System.Linq.Enumerable.Where ,but I don't know how to iterate through strFull items. What could be the quickest way to do so ?

Thanks in advanced.



dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 edited

I think that you can write:

 Dim result As IEnumerable(Of String) = ar2.Except(ar1)

If you are interested in Where:

 Dim strFull As IEnumerable(Of String) = ar1.Intersect(ar2)
 Dim result As IEnumerable(Of String) = ar2.Where(Function(a2) Not strFull.Contains(a2))


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.