Hi, I have two Arrays/Lists:
List/Array 1: A,B,C,D
List/Array 2: A,B,E
I want to retrieve the elements which are Not in common. One expression for those not in common and contained in 1 and another for those in 2
so. if main collection is 1, result is C,D
if main collection is 2, result is E
Edit: Comparison is case insensitive, trim whitespace
How do I do this?
Yoichi
(Yoichi)
August 25, 2020, 4:37am
2
Hi,
Can you try the following expression?
if main collection is 1, result is C,D
list1.Where(Function(x) not list2.Contains(x)).toList()
if main collection is 2, result is E
list2.Where(Function(x) not list1.Contains(x)).toList()
Regards,
2 Likes
Hi @Yoichi , how do you modify this to be case insensitive and ignore whitespace?
Yoichi
(Yoichi)
August 25, 2020, 5:50am
4
Hi,
how do you modify this to be case insensitive and ignore whitespace?
How about the following?
list1.Where(Function(x) not list2.Select(Function(y) y.Trim().ToLower()).Contains(x.Trim().ToLower())).toList()
Regards,
1 Like
@Yoichi
Thanks, How do you efficiently convert all the elements in the List above back to Uppercase?
Yoichi
(Yoichi)
August 25, 2020, 8:51am
6
Hi,
The above expression converts to lower case only for evaluation. So, result list has original string.
If you want to convert all the items of the list to upper case, the following will work.
list3.Select(function(x) x.ToUpper()).toList()
Regards,
1 Like
@Yoichi Hi, I used this code
list1.Where(Function(x) not list2.Select(Function(y) y.Trim().ToLower()).Contains(x.Trim().ToLower())).toList()
and I ended up with list items with blank content (e.g. “”, " " etc…) how do I remove these?
Yoichi
(Yoichi)
August 26, 2020, 10:16am
8
Hi,
How about the following?
list1.Where(Function(x) not list2.Select(Function(y) y.Trim().ToLower()).Contains(x.Trim().ToLower()) AndAlso Not String.IsNullOrWhiteSpace(x)).toList()
Regards,
1 Like
loginerror
(Maciej Kuźmicz)
Split this topic
May 12, 2021, 9:53am
9
2 posts were merged into an existing topic: Date time questions