【问题标题】:Multiple Strings in One String with Or一个字符串中的多个字符串与或
【发布时间】:2015-09-23 11:33:54
【问题描述】:

我想检查 indexpage 字符串 witf If 中的每个字符串。这是索引页

Dim indexpage As String = "string1" Or "string2"

我尝试过括号 OrElse 但它没有用.. 而且这不是 If 函数的问题。当我在没有 If 函数的情况下尝试它时,它仍然给我这个错误......

错误:

An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll

Additional information: Conversion from string "string1" to type 'Boolean' is not valid.

【问题讨论】:

标签: vb.net string boolean


【解决方案1】:

感谢 James Thorpe,我找到了答案。

Dim testAgainst As String() = {"02","03","06","07"}

还有 If 函数

    If testAgainst.Contains(WebControl1.Source.ToString) Then
        ' code
    Else
        ' code
    End If

【讨论】:

    猜你喜欢
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多