1

在下面提供的代码中,我有一个测试数组。我想查找那些在 400 到 500 范围内但在 Test 数组 ( Ex: 410 - Although this value is in the range of 400 to 500, it is not found in the array)中找不到set the value of it to 410|New-value的值网页。

这是代码:

Test= Array("1|Name", "2|Place", "400|Animal", "420|Thing")

For Each x in Test
    xSplit=Split(x,"|")
    'Do Something'          
Next    
    'Do Something'

有人可以帮我吗?

4

1 回答 1

1

显然你在那里有键/值对,所以适当的数据结构可能是一个字典

Set dict = CreateObject("Scripting.Dictionary")
For Each x in Test
  xSplit = Split(x, "|")
  dict.Add xSplit(0), xSplit(1)
Next

这样您就可以轻松检查键值是否存在:

If dict.Exists(42) Then
  WScript.Echo dict(42)
Else
  WScript.Echo "Index 42 does not exist."
End If
于 2012-09-12T10:04:57.807 回答