Check List for multiples of a String

Hello

I am trying to search through a List of Strings to see if a specific String appears more than once.
Basically I have an if statement that I want to be True is the List contains the String at least twice

List:
dog
cat
mouse
dog

String: “dog”

if (List.Contains(“dog”)
would work if I am just checking for any instance of dog but I need to check for more than one.

@GoldCutlery
can be done with the help of count
If condition:
yourListVar.Where(function (s) s.equals(YoursearchtermVar)).Count() >1

1 Like

Also could be like this if you will need to find all duplicates in the list:
listOfDuplicates = list.GroupBy(Function(m) m).Where(Function(g) g.Count() > 1).Select(Function(g) g.Key).ToList

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.