String.Contains Case Sensitive

String.Contains Case Sensitive
Case Sensitive String.Contain
String.Contains vs IndexOf .Net

I encountered an issue with string contains couple of days ago... well, the fact is - it has no
StringComparison for culture and Case Sensitivity.

I found a better way to do this, and I just wanted to share in a short post:

        string bookTitle = "The Old Man and the Sea";

        if (bookTitle.IndexOf("the old man") > -1)
            // this is case sensitive
        if (bookTitle.IndexOf("the old man", StringComparison.OrdinalIgnoreCase) > -1)
            // this is ignore case

There are some more options in the StringComparison , but I'll leave it to you to play with

Good day,
Elad Shalom,
CTO at


  1. Hi, Neat post. There's an issue with your site in internet explorer, may
    check this? IE still is the marketplace leader and a big
    part of other people will leave out your magnificent writing due to this problem.

    Stop by my site: home inspection brooklyn


Post a Comment

Popular posts from this blog

Linked Files in Visual Studio 2010

Cloud Computing Advantages and Disadvantages

Protecting Personal Data