Case Insensitive comparison in C#

c#, comparison, string

Solution

Try this:

string.Equals("this will return true", "ThIs WiLL ReTurN TRue", StringComparison.CurrentCultureIgnoreCase)

Or, for contains:

if (string1.IndexOf(string2, StringComparison.CurrentCultureIgnoreCase) >= 0)

Problem

I am comparing two strings using following code string1.Contains(string2) but i am not getting results for case insensitive search. Moreover I cant use String.Compare coz i dont want to match the whole name as the name is very big. My need is to have case insensitive search and the search text can be of any length which the String1 contains. Eg Term************** is the name. I enter "erm" in textbox den i get the result. but when i enter "term" i dont get any result. Can anyone help me :)

Original source

Related problems