You can split your string using: youstringvariable.Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries)
This will remove empty entries and you will get an array[string].
The you can do: youarray.GroupBy(Function(w) w).OrderByDescending(Function(g) g.Count())
This will give you list of each entry in the array grouped together in descending order.
your case you will get
When you do- list(0).count >1 you have a duplicate and
list(0) will give you that item value.
You can check where total number of records in the list are equal to total number of distinct records in the list. Total number of records can be determined by Count property and distinct records can be determined by using Distinct method of List object.
list.Count = list.Distinct().Count()
if true, No duplicates. Otherwise, contains duplicate records.
This outputs the duplicate value BUT if there is more than 1 duplicate value then it only outputs óne of them. So the problem (right now) is that i dont know what syntax to use to output all duplicates in the array.
Found your suggestion seems matching what I need for checking whether a new value is duplicated in a column…
What i did…
read range > for each row in dt
Assign subDom = row(1).ToString **Variable type: String
Assign ListCol = new List(of String) **Variable type: List String
Add to collection Collection: ListCol item: subDom TypeArgument: String
For each item in ListCol
If ListCol.Count = ListCol.Distinct().Count()
Then Message Box “not duplicated” Else" duplicated"
Write Line Text item.ToString (This activity is just for testing whether I got the right content for ListCol)
Output 1 2 2 4 5 No error No Warning
But Message Box Popup 5 times “not duplicated” which is not correct.
Can you help me what I’m missing?
If your intention is to check whether a column in datatable has duplicate values, you can use a linque query and check this.
dtDataTable.AsEnumerable().Select(function(x) x.Field(of String)(“Column_Name”)).GroupBy(function(x) x).Where(function(g) g.Count() > 1).ToList().Count
But if you have a requirement to loop through to do additional functionalities, then you can use filter datatable activity by passing the column value for the row and check how many resultant rows are retrieved.
What I try to do is if a new entry of username in the new row is duplicated to the other row in column “username”, Then send an email to user to change, Else continue to another task.
I checked the filter datatable activity, but it seems only output “filtered DataTable variable”, not a boolean as I need.
So I tried the first suggestion from you, but not sure what are “x” and “g” for
dt.AsEnumerable().Select(function(x) x.Field(of String)(“username”)).GroupBy(function(x) x).Where(function(g) g.Count() > 1).ToList().Count
But got error Option Strict On not allow from ‘Integer’ to ‘Boolean’…