How can I make the following case insensitive?
myString1.Contains("AbC")
bool b = list.Contains("Hello", StringComparer.CurrentCultureIgnoreCase);
[EDIT] extension code:
public static bool Contains(this string source, string cont , StringComparison compare) { return source.IndexOf(cont, compare) >= 0; }
This could work :)
You can use:
if (myString1.IndexOf("AbC", StringComparison.OrdinalIgnoreCase) >=0) { //... }
This works with any .NET version.
You can create your own extension method to do this:
public static bool Contains(this string source, string toCheck, StringComparison comp) { return source != null && toCheck != null && source.IndexOf(toCheck, comp) >= 0; }
And then call:
mystring.Contains(myStringToCheck, StringComparison.OrdinalIgnoreCase);