Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com
I wanted to have case-insensitive Contains method for list of strings.
Overload Enumerable.Contains<TSource> Method (IEnumerable<TSource>, TSource, IEqualityComparer<TSource>) expects custom IEqualityComparer class.I was about to create my own class IgnoreCaseEqualityComparer : IEqualityComparer<string>,
but then found StringComparer.Create Method, that allow to use standard class.

public static bool ContainsString(this IEnumerable<string> collection, string toFind, bool ignoreCase = true)
{
return collection.Contains(toFind,
StringComparer.Create(CultureInfo.InvariantCulture, ignoreCase));
}
Posted on Wednesday, April 18, 2012 10:29 PM .Net Framework , Helper Functions | Back to top


Comments on this post: Case-insensitive Contains extension for list of strings

# re: Case-insensitive Contains extension for list of strings
Requesting Gravatar...
Alternatively, you can use StringComparer.InvariantCultureIgnoreCase directly.
Left by Bernard Vander Beken on Feb 09, 2016 9:20 PM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net