Creating a Case-Insensitive TextBox

Tyecom

Well-known member
Joined
Aug 8, 2007
Messages
78
Programming Experience
Beginner
I have a TextBox that need to be case-insensitive. For example, I have this code: If searchTextBox.Text = "Park" Then... I need results back if "Park" is typed or "park". Any help would be greatly appreciated.
 
Another option would be to use String.Compare. The first 2 parameters are the strings and the third is ignoreCase.

VB.NET:
		If String.Compare(Me.uxSearch.Text, "Park", True) Then
			'...
		End If
 
ignoreCase: A System.Boolean indicating a case-sensitive or insensitive comparison. (true indicates a case-insensitive comparison.)

Seems to be working backwards from how I read it. I have to set it to False to get an insensitive comparisson.

VB.NET:
		Me.uxSearch.Text = "PARK"

		If String.Compare(Me.uxSearch.Text, "Park", False) Then
			MessageBox.Show("Match")
		Else
			MessageBox.Show("No Match")
		End If
 
Picoflop and MattP,

Thank you both for providing these solutions. Both worked really well! Thanks again.
 
if your query is to a database, lower all the data:

SQL:
SELECT * FROM person WHERE LOWER(name) = :personName

Code:
command.Parameters.Add("personName", txtPersonName.Text.ToLower())
 
Back
Top