Forum Discussion
Kenn
7 months agoNew Contributor
Removing Duplicates from a Member Filter
Hi All, I have the following use case whereby in my parameter, I have a member list of C#Local,C#USD,C#JPY,C#|WFText2| whereby WFText2 will be currencies/consolidation members eg. CNY,EUR,SGD,USD...
- 7 months ago
Hi Kenn
If you are working with a Member List you can use something like this Linq syntax (see vb example below).
** This assumes that we are using object Member in our list and therefore we can access Name property
Dim List(of Member) distinctByName = yourMemberList _ .GroupBy(Function(p) p.Name) _ .Select(Function(g) g.First()) _ .ToList()This will get the First instance of duplicate e.g C#Local in your example. If you want Last, simply change syntax to be .Last() instead
Hope this helps
Sam
MarcusH
7 months agoValued Contributor
I am assuming that when you say 'member list' you mean a text string that contains a list of members rather than an object which is List(Of Member). You can use a hashset for that like this:
Dim input As String = "C#Local,C#USD,C#JPY,C#USD"
' Split the string by commas
Dim members() As String = input.Split(","c)
' Use a HashSet to filter unique members efficiently
Dim uniqueMembers As New HashSet(Of String)(members)
' Join back the unique members into a string
Dim result As String = String.Join(",", uniqueMembers)
Related Content
- 2 years ago
- 2 years ago