如何在经典ASP中相互使用两个Split()函数?

时间:2022-05-18 11:40:27

I have two variables (getYear and getBranch) in my page.

我的页面中有两个变量(getYear和getBranch)。

getYear-1,4,11
getBranch-4,5,7

GetYearSingle = Split(getYear, ",")

I get single array value after Split() function like this:

我在Split()函数之后得到单个数组值,如下所示:

For Each iLoop In GetYearSingle
  response.write "<br>Year= " & iLoop
Next

I get result like this

我得到这样的结果

year=1
year=4
year=11

but I need result like this

但我需要这样的结果

year=1
Branch=4

year=4
Branch=5

year=11
Branch=7

2 个解决方案

#1


1  

Going out on a limb I'll assume that

走出困境,我会假设

getYear-1,4,11
getBranch-4,5,7

was actually meant to look like this:

实际上看起来像这样:

getYear = "1,4,11"
getBranch = "4,5,7"

If that's the case you want to split both strings at commas and use a For loop (not a For Each loop) to iterate over the elements of both arrays.

如果是这种情况,您希望以逗号分隔两个字符串并使用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

#2


1  

You need to loop over both arrays via the (syncronized) index:

您需要通过(同步)索引遍历两个数组:

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

output:

cscript 44118915.vbs
Microsoft (R) Windows Script Host, Version 5.812
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

1 4
4 5
11 7

#1


1  

Going out on a limb I'll assume that

走出困境,我会假设

getYear-1,4,11
getBranch-4,5,7

was actually meant to look like this:

实际上看起来像这样:

getYear = "1,4,11"
getBranch = "4,5,7"

If that's the case you want to split both strings at commas and use a For loop (not a For Each loop) to iterate over the elements of both arrays.

如果是这种情况,您希望以逗号分隔两个字符串并使用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

#2


1  

You need to loop over both arrays via the (syncronized) index:

您需要通过(同步)索引遍历两个数组:

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

output:

cscript 44118915.vbs
Microsoft (R) Windows Script Host, Version 5.812
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

1 4
4 5
11 7