How to ignorecase when using string.text.contains?
I'm not a vb.net programmer, but according to Microsoft, you can get the lowercase/uppercase value of the text using the string methods ToUpper()
or ToLower()
. You can then compare that with "my house is cold"
or "MY HOUSE IS COLD"
.
Dim myhousestring As String = "MY HOUSE IS COLD"
If txt.Text.ToUpper.Contains(myhousestring) Then
Messagebox.Show("Found it")
End If
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.