gpt4 book ai didi

vb.net - 不区分大小写

转载 作者:行者123 更新时间:2023-12-04 16:27:38 25 4
gpt4 key购买 nike

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

我试图让用户输入的字母 a,b,c,d 不敏感。尝试使用 UCase,但它不起作用(不确定我是否使用错误)。我在 Visual Studio 2012 中使用 VB。任何引用都会很棒。

最佳答案

您可以使用 String.Compare方法:String.Compare (String strA, String strB, Boolean ignoreCase)
通行证ignoreCasetrue 的争论将执行不区分大小写的比较。

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

另一个想法是使用 ToUpper 将输入大写或小写或 ToLower .
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

关于vb.net - 不区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15606701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com