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
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
Or you can use RegularExpressions like this.
First, import the RegularExpressions:
Imports System.Text.RegularExpressions
then try this code:
Dim match As Match = Regex.Match(Textbox1.text,"My house is cold",RegexOptions.IgnoreCase)
If match.Success Then
Msgbox(match.Value)
End If
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