How to ignorecase when using string.text.contains?

后端 未结 9 813
情深已故
情深已故 2021-01-07 18:11

I am trying to figure out how to check if a string contains another while ignoring case using .text.contains.

As it stands right now If I do this:

 D         


        
9条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 19:04

    Personally I just used:

    item.Text.ToLower().Contains("my house is cold")
    

    you could just as well use ToUpper as well.

    Caveat: If you are comparing Turkish, or other languages, the ToLower() and ToUpper() also take an option parameter, for "CultureInfo" allowing you to ensure that different languages are handled correctly. You can use an above solution, or you can follow the steps from Microsoft's ToLower Documentation, to add in CultureInfo, to get ToLower context on which language you are about to try to manipulate.

    ToLower() with CultureInfo documentation

    ToUpper() with CultureInfo documentation

提交回复
热议问题