How to ignorecase when using string.text.contains?

后端 未结 9 818
情深已故
情深已故 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 18:52

    According to Microsoft you can do case-insensitive searches in strings with IndexOf instead of Contains. So when the result of the IndexOf method returns a value greater than -1, it means the second string is a substring of the first one.

    Dim myhousestring As String = "My house is cold"
    If txt.Text.IndexOf(myhousestring, 0, StringComparison.CurrentCultureIgnoreCase) > -1 Then
        Messagebox.Show("Found it")
    End If
    

    You can also use other case-insensitive variants of StringComparison.

提交回复
热议问题