Case insensitive String.Contains for C#

So, you want to use the String.contains method but you want it to be case insensitive.
You can use the following test instead:

string s = "MYSTRING";
if( s.IndexOf("string", 0, StringComparison.CurrentCultureIgnoreCase) != -1 )
{
    // String contains "string"
}
else
{
   // String does not contain "string"
}

We use "-1" because "0" can be an index

Popular posts from this blog

Syslog Message Collection for OMS from sources that do not support the agent

How to Configure Message Forwarding on a Mailbox Level

Building a PowerShell cmdlet using C# - Part 1: Basic Code and Requirements