2017-05-22 27 views
0

我在頁面中有兩個變量(getYeargetBranch)。如何在傳統的ASP中使用兩個Split()函數?

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 

回答

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

您需要循環經由(syncronized)索引二者陣列:

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