String Ends With Values in Array of Strings

String Ends With Values in Array of Strings
This simple method checks if a string ends with either of the values in an array of characters, and returns true if it does. Useful to add appropriate suffixes to words in standard form.
1.public static bool EndsIn(this string o, string[] c)
2.{
3.    foreach (string i in c) // Loop through the possible endings
4.    {
5.        if (o.EndsWith(i)) // If any matches
6.            return true; // Return true
7.    }
8.    return false;
9.}

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top