语句判断时,如何不区分字符串的大小写

 

第一:用if……end if 判断

Public Class Form1

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
        Dim strName As String
        strName = txtName.Text
        If String.Compare(strName, "BRYAN", True) = 0 Then  '选true时,不区分大小写,字符串匹配,返回0,选false时,区分大小写,字符串不匹配,返回-1
            MsgBox("Hello, Bryan!", vbOKOnly Or MsgBoxStyle.Information, "忽略大小写试验")
        End If
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

End Class

第二:用 select case 判断

 

Public Class Form1

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
        Dim strName As String
        strName = txtName.Text
        Select Case strName.ToUpper     '把字符串转换成大写
            Case "A"
                txtName.Text = "Madras Yellow"
            Case "B"
                txtName.Text = "Sea Blue"
            Case "C"
                txtName.Text = "Morning Mist"
            Case "D"
                txtName.Text = "Passionate Purple"
            Case "E"
                txtName.Text = "Red"
            Case Else
                txtName.Text = "数据越界"
        End Select
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

End Class

你可能感兴趣的:(VB,net,2010,区分大小写)