我的页面中有两个变量(getYear
和getBranch
)。
getYear-1,4,11
getBranch-4,5,7
GetYearSingle = Split(getYear, ",")
我在Split()
函数之后得到单个数组值:
For Each iLoop In GetYearSingle
response.write "<br>Year= " & iLoop
Next
我得到这样的结果
year=1 year=4 year=11
但我需要这样的结果
year=1 Branch=4 year=4 Branch=5 year=11 Branch=7
答案 0 :(得分:1)
走出困境我会假设
getYear-1,4,11
getBranch-4,5,7
实际上看起来像这样:
getYear = "1,4,11"
getBranch = "4,5,7"
如果是这种情况,你想用逗号分割两个字符串并使用For
循环(而不是For Each
循环)迭代两个数组的元素。
arrYear = Split(getYear, ",")
arrBranch = Split(getBranch, ",")
For i = 0 To UBound(arrYear)
response.write "<br>Year= " & arrYear(i)
response.write "<br>Branch= " & arrBranch(i)
Next
答案 1 :(得分:1)
您需要通过(同步)索引遍历两个数组:
Option Explicit
Dim y : y = Split("1,4,11", ",")
Dim b : b = Split("4,5,7", ",")
If UBound(y) = UBound(b) Then
Dim i
For i = 0 To UBound(y)
WScript.Echo y(i), b(i)
Next
End If
输出:
cscript 44118915.vbs
Microsoft (R) Windows Script Host, Version 5.812
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
1 4
4 5
11 7