I have an array, containing some strings split by a comma. I would like to count the amount of duplicate strings and set the number to a variable with the name of the item that appears the most. An example array is below:
“Postage”, “Registry”, “Registry”, “Registry”, “Registry”, “Search Fees”, “Registry”, etc.
The strings in the array will differ almost every time, as will the amount in the array, so I cannot look for specific words or locations. Does anybody have any suggestions on counting the duplicate strings?
getting the duplicates only you can modify e.g.:
(From x In arrValues
Group x By k=x Into grp=Group
Where grp.Count > 1
Select dtReport.Rows.Add({k,grp.Count})).CopyToDataTable
Here’s how I would do it: parse the string and create a dictionary with the words as the keys and the values as init counters. If the new work is in the dictionary, increase the counter of that key. Of not, add the new key with the value 1.
I followed the steps in the topic you linked, and the validation error went away. I tried with the array you and @prasath17 used and my array of strings which worked brilliantly.