我的页面中有两个变量(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
我得到这样的结果
年=1年=4年=11
但我需要这样的结果
年=1分支=4年=4分支=5年=11分支=7
四肢外出,我会假设
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
您需要通过(同步(索引遍历两个数组:
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