Skip to content

Instantly share code, notes, and snippets.

@lemmit
Created January 12, 2017 09:49
Show Gist options
  • Save lemmit/0e89fdff7ad48cef932cd47df2e7336f to your computer and use it in GitHub Desktop.
Save lemmit/0e89fdff7ad48cef932cd47df2e7336f to your computer and use it in GitHub Desktop.
public static class CaseInsensitiveStringExtensions
{
public static bool CaseInsensitiveContains(this string source, string toCheck)
{
return source.IndexOf(toCheck, StringComparison.OrdinalIgnoreCase) >= 0;
}
public static bool CaseInsensitiveStartsWith(this string source, string startsWith)
{
return source.EndsWith(startsWith, StringComparison.OrdinalIgnoreCase);
}
public static bool CaseInsensitiveEndsWith(this string source, string endsWith)
{
return source.EndsWith(endsWith, StringComparison.OrdinalIgnoreCase);
}
public static bool CaseInsensitiveEquals(this string source, string str)
{
return source.Equals(str, StringComparison.OrdinalIgnoreCase);
}
public static int CaseInsensitiveCompare(this string source, string str)
{
return string.Compare(source, str, StringComparison.OrdinalIgnoreCase);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment