Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if String ends with something from a list. C#

Tags:

c#

list

ends-with

I want to take a user's input, and check if the end of what they put in ends with something. But it's more than one string. I have it in a list. And I could check if the input ends with a string from the list one by one. However, I would just like to check if the input ends with anything from a list.

like image 854
Nathan Bel Avatar asked Jun 11 '16 20:06

Nathan Bel


1 Answers

If "endings" is a List<string> that contains the possible endings to match:

if (endings.Any(x => userInput.EndsWith(x)))
{
    // the string ends with something in the list
}
like image 162
wablab Avatar answered Oct 12 '22 14:10

wablab