Check whether a string is not equal to any of a list of strings

后端 未结 4 1688
野性不改
野性不改 2021-02-19 06:29

Is there a way to convert some code like this:

If someString <> \"02\" And someString <> \"03\" And someString <> \"06\" And someString <>         


        
4条回答
  •  执笔经年
    2021-02-19 07:22

    You can (ab)use Select for this in simple cases:

    Select Case someString
        Case "02", "03", "06", "07"
        Case Else
            btnButton.Enabled = False
    End Select
    

    Also, a common extension that I use is:

    
    Function [In](Of TItem, TColl)(this As TItem, ParamArray items() As TColl)
        Return Array.IndexOf(items, this) > -1
    End Function
    

    So:

    If Not someString.In("02", "03", "06", "07") Then
        btnButton.Enabled = False
    End If
    

提交回复
热议问题