I have some lines of text. I used regex to get some values. It return all matched values. From those values, I need to get duplicate values. Please help me.
Hi @qbss
Use linq group by and take count…if count is more than 1 its duplicate.
for ref How to: Count, Sum, or Average Data by Using LINQ - Visual Basic | Microsoft Learn
2 Likes
Please update the query.
I tried the below query,
lst.GroupBy(x => x)
.Where(g => g.Count() > 1)
.Select(y => y.Key)
.ToList();
But it not working
if you want remove duplicates you can use “Distinct”
Go Through the following example.
Dim MyTable = { _
New With {.ID = 1, .Name = "record 1", .Status = "Outstanding"},
New With {.ID = 2, .Name = "record 2", .Status = "Outstanding"},
New With {.ID = 3, .Name = "record 3", .Status = "Aging"},
New With {.ID = 4, .Name = "record 4", .Status = "Outstanding"},
New With {.ID = 5, .Name = "record 5", .Status = "Aging"},
New With {.ID = 6, .Name = "record 6", .Status = "Outstanding"}
}
Dim dataTable = _
From item In MyTable
Group By Key = item.Status Into Xs = Group
Select New With {.Status = Key, .Count = Xs.Count()}
From the result you can filter with count.
For my case, if the value appears more than once, then it should be captured.
you can use datatable