Skip to content

Instantly share code, notes, and snippets.

@icodeintx
Last active March 14, 2023 19:41
Show Gist options
  • Save icodeintx/2963be7f166ffc784683999c5e225a47 to your computer and use it in GitHub Desktop.
Save icodeintx/2963be7f166ffc784683999c5e225a47 to your computer and use it in GitHub Desktop.
String List Comparison
// A nice way to find out if a string contains any value in a string list
using System.Linq;
public static bool ContainsAny(string s, List<string> substrings)
{
if (string.IsNullOrEmpty(s) || substrings == null)
return false;
return substrings.Any(substring => s.Contains(substring, StringComparison.CurrentCultureIgnoreCase));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment