gpt4 book ai didi

arrays - 检查经典 asp 数组中的变量是否存在

转载 作者:行者123 更新时间:2023-12-02 04:43:31 24 4
gpt4 key购买 nike

我正在尝试检查变量的值是否在数组中。遇到一些困难。我的数组存储在 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")

但我想要一种更优雅的方式来使用数组来完成此操作。

帮助不大。谢谢。

最佳答案

没有内置的 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

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

关于arrays - 检查经典 asp 数组中的变量是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36794560/

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