1
votes

If I type:

if TextBox1.Text = "Hello" Then MsgBox("Test")

I would like to know how to enable that so people could type for example "hElLo" instead of "Hello", or "hello".

2
Textboxes don't spellcheck, they allow any input. - AStopher
You have to do spell check on your own by making case sensitive checks - Mr37037
Also: appears to be a duplicate of: stackoverflow.com/questions/14395625/… - AStopher
This was a pretty controversial post: puu.sh/du5Gp/9f51f09514.png - AStopher

2 Answers

1
votes

You want to compare case-insensitive, use the appropriate StringComparison in String.Equals:

If String.Equals(TextBox1.Text, "Hello", StringComparison.CurrentCultureIgnoreCase) Then
    ' ... '
End If

You can also use the non-shared Equals in the same way, the difference is that it throws an exception if the first string is Nothing which is impossible in this case:

If TextBox1.Text.Equals("Hello", StringComparison.CurrentCultureIgnoreCase) Then
    ' ... '
End If
1
votes

You want to convert the whole string to lower-case and then perform the check as per se:

If TextBox1.Text.ToLower = "hello" Then
   MsgBox("Test")
End If

As pointed out by Tim Schmelter, the above code does not pass the so-called 'Turkey Test' (it's an interesting read, and something that I hadn't heard about before).

If you plan to use your code on a system with a non-ASCII standard locale, you should instead use:

If String.Equals(TextBox1.Text, "hello", StringComparison.CurrentCultureIgnoreCase) Then
   MsgBox("Test")
End If

Remember that the string to compare also must be lower-case if you must use the first code example that failed the Turkey Test.