在ASP中如何遍历数组?
<%
' 创建一个固定数组
dim companies(2)
' 填充数组
set companies(0) = Company1
set companies(1) = Company2
set companies(2) = Company3
' 遍历数组方法1
dim company
for each company in companies
response.write company '公司名
next
' 遍历数组方法2
dim i
for i = 0 to ubound(companies)
response.write companies(i) '公司名
next
%>
在ASP中如何遍历集合?
<%
dim cars(2),x
cars(0)="Volvo"
cars(1)="Saab"
cars(2)="BMW"
For Each x in cars
response.write(x & " ")
Next
%>
在ASP中如何遍历字典:
<%
dim Cars
set Cars = server.createObject("Scripting.Dictionary")
' 新增cars
Cars.add "电动车", "蔚蓝"
Cars.add "油电混合", "吉利"
Cars.add "新能源", "比亚迪"
' 遍历方法1:
dim key
for each key in Cars.keys
response.write key & " = " & Cars(key) & vbcrlf
next
' 遍历方法2:
Dim objKeys, objItems, i
objKeys = Cars.Keys
objItems = Cars.Items
For i = 0 To Cars.Count -1
response.Write "Key=" & objKeys(i) & " AND Value=" & objItems(i) & vbcrlf
Next
%>