Vb.net 不区分大小写
我试图使用户输入的字母a、b、c、d不敏感。尝试使用UCase,但不起作用(不确定是否使用错误)。我在Visual Studio 2012中使用VB。任何引用都很好。您可以使用方法:Vb.net 不区分大小写,vb.net,visual-studio,case-insensitive,Vb.net,Visual Studio,Case Insensitive,我试图使用户输入的字母a、b、c、d不敏感。尝试使用UCase,但不起作用(不确定是否使用错误)。我在Visual Studio 2012中使用VB。任何引用都很好。您可以使用方法:String.Compare(String-strA、String-strB、Boolean-ignoreCase) 使用true传递ignoreCase参数将执行不区分大小写的比较 If TextBox2.Text = "a" AndAlso TextBox21.Text = "a" Then 'M
String.Compare(String-strA、String-strB、Boolean-ignoreCase)
使用true
传递ignoreCase
参数将执行不区分大小写的比较
If TextBox2.Text = "a" AndAlso TextBox21.Text = "a" Then
'MessageBox.Show("A")
totCorrect = totCorrect + corAns
ElseIf TextBox2.Text = "b" AndAlso TextBox21.Text = "b" Then
'MessageBox.Show("B")
totCorrect = totCorrect + corAns
ElseIf TextBox2.Text = "c" AndAlso TextBox21.Text = "c" Then
'MessageBox.Show("C")
totCorrect = totCorrect + corAns
ElseIf TextBox2.Text = "d" AndAlso TextBox21.Text = "d" Then
'MessageBox.Show("D")
totCorrect = totCorrect + corAns
Else
totWrong = totWrong + wrgAns
Label13.Visible = True
End If
另一个想法是使用or将输入大写或小写
根据VB.NET中的MSDN,只需向文件中添加1行代码即可使用:
选项比较文本
如果将上述行添加到代码开头,则说明CLR从默认值(选项Compare Binary
)切换到不区分大小写的比较,作为=
运算符的新默认值
我不知道是否有其他选择。请看:谢谢,这非常有用
If String.Compare(TextBox2.Text, "a", true) = 0 AndAlso String.Compare(TextBox21.Text, "a", true) = 0 Then
'MessageBox.Show("A")
totCorrect = totCorrect + corAns
ElseIf String.Compare(TextBox2.Text, "b", true) = 0 AndAlso String.Compare(TextBox21.Text, "b", true) = 0 Then
'MessageBox.Show("B")
totCorrect = totCorrect + corAns
ElseIf String.Compare(TextBox2.Text, "c", true) = 0 AndAlso String.Compare(TextBox21.Text, "c", true) = 0 Then
'MessageBox.Show("C")
totCorrect = totCorrect + corAns
ElseIf String.Compare(TextBox2.Text, "d", true) = 0 AndAlso String.Compare(TextBox21.Text, "d", true) = 0 Then
'MessageBox.Show("D")
totCorrect = totCorrect + corAns
Else
totWrong = totWrong + wrgAns
Label13.Visible = True
End If
If TextBox2.Text.ToUpper() = "A" AndAlso TextBox21.Text.ToUpper() = "A" Then
'MessageBox.Show("A")
totCorrect = totCorrect + corAns
ElseIf TextBox2.Text.ToUpper() = "B" AndAlso TextBox21.Text.ToUpper() = "B" Then
'MessageBox.Show("B")
totCorrect = totCorrect + corAns
ElseIf TextBox2.Text.ToUpper() = "C" AndAlso TextBox21.Text.ToUpper() = "C" Then
'MessageBox.Show("C")
totCorrect = totCorrect + corAns
ElseIf TextBox2.Text.ToUpper() = "D" AndAlso TextBox21.Text.ToUpper() = "D" Then
'MessageBox.Show("D")
totCorrect = totCorrect + corAns
Else
totWrong = totWrong + wrgAns
Label13.Visible = True
End If