"" and info <> "links" and info <> "privacy" and info <> "-6ren">
gpt4 book ai didi

arrays - 如何检查vbscript中数组中的变量

转载 作者:行者123 更新时间:2023-12-02 05:40:47 27 4
gpt4 key购买 nike

我正在重构我的代码并尝试减少重复。我有这个工作代码

<% If tree <> "" or (info <> "" and info <> "links" and info <> "privacy" and info <> "talks") Then %>
write stuff
<% End If %>

我将信息变量放入一个数组中

Dim info(3)
info(0) = "Talks"
info(1) = "Privacy"
info(2) = "Links"

我不清楚遍历数组

<% If tree <> "" or (info <> "" and **info <> arrayInfo** Then %>
write stuff
<% End If %>

帮助不大。谢谢。

最佳答案

如果您想使用one 表达式(.Exists) 来获取关于集合的所有 元素的事实(包含或不包含),则需要字典。看看:

Option Explicit

Dim aInfo(2) ' last index; not size
aInfo(0) = "Talks"
aInfo(1) = "Privacy"
aInfo(2) = "Links"
Dim dicInfo : Set dicInfo = CreateObject("Scripting.Dictionary")
dicInfo.CompareMode = vbTextCompare
Dim i
For Each i In aInfo
dicInfo(i) = 0
Next
For Each i In Split("Talks Other Links Else")
If dicInfo.Exists(i) Then
WScript.Echo i, "found"
Else
WScript.Echo "no", i, "in", Join(dicInfo.Keys())
End If
Next

输出:

cscript 42207316.vbs
Talks found
no Other in Talks Privacy Links
Links found
no Else in Talks Privacy Links

关于arrays - 如何检查vbscript中数组中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42207316/

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