Home > Back-end >  c# string .Startwith() any string from List<string>
c# string .Startwith() any string from List<string>

Time:11-10

I have a list of strings in example:

['xxx', 'xxxyy', 'ccccy']

and a normal string i.e. String example1 = "xxxyyy"

And I want to check if any of the strings in my list matches start of my example1 I dont need to know which strings match but only if example1 starts with any of the strings in the list.

CodePudding user response:

You can use LINQ for that like this:

if (yourArray.Any(a => example1.StartsWith(a))
  • Related