String.Content How to Not Case Sensitive

Asked

Viewed 36 times

1

Well I have a string where I want to search for a word but not case sensitive

Example:

string tt2 = "teste amanha de manha";
string pp = "Amanha";
if (tt2.Contains(pp))
{
//Não entra na condição pois na string o amanha tem o "a" em minusculo
}
  • 2

    you can put the stringin high or low box with string.ToUpper() or string.ToLower()

  • @Jcsaint gambiarra. Works only by coincidence.

1 answer

2


With the method Contains is not possible, but one can have the expected result with the method IndexOf

string tt2 = "teste amanha de manha";
string pp = "Amanha";
if (tt2.IndexOf(pp, StringComparison.CurrentCultureIgnoreCase) > -1)
{
    //agora ele entra aqui
}
  • It worked, simple and effective, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.