【问题标题】:Check if variable in classic asp array检查经典asp数组中的变量是否
【发布时间】:2016-04-22 13:00:05
【问题描述】:

我正在尝试检查变量的值是否在数组中。有一些困难。我的数组存储在 global.asa 中。

    Dim aTree(5)
   aTree(0) = "a"
    aTree(1) = "b"
    aTree(2) = "c"
    aTree(3) = "d"
    aTree(4) = "e"
    aTree(5) = "f"
       Application("aTree") = aTree 

我要检查的变量存储了一些 html 内容

<% If tree = "a" Then %>
     <div class="card bg_white">
            <h1 class="bold small-caps tbrown">my content</h1>
    </div>
<% End If %>

我正在尝试以这种方式进行检查

<% tree = Request("tree") 
if in_array(tree, aTree) then %>
You've found it
<% End if %>

我有这个可以运行的笨重版本

(tree <> "" and tree <> "a" and tree <> "b" and tree <> "c" and tree <> "d" and tree <> "e" and tree <> "f")

但我想要一种更优雅的方式来使用数组。

帮助不大。谢谢。

【问题讨论】:

    标签: arrays variables asp-classic


    【解决方案1】:

    没有内置的InArray() 函数,但它应该足够简单,可以自己构建。

    Function InArray(theArray,theValue)
        dim i, fnd
        fnd = False
        For i = 0 to UBound(theArray)
            If theArray(i) = theValue Then
                fnd = True
                Exit For
            End If
        Next
        InArray = fnd
    End Function
    

    修改此函数以返回值的索引而不仅仅是真/假,留给读者作为练习。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      相关资源
      最近更新 更多