问题描述
我试图在VBScript中将多个字符串添加到多维数组中.我希望我可以简短地解释一下:每个字符串都包含一些用逗号分隔的数据.现在,我想将所有这些数据添加到一个数组中,每个字符串一个维.
I am trying to add multiple strings into a multidimensional array in VBScript. I hope I can explain it in a short way:Every string contains some data separated by commas. Now I would like to add all these data into an array, one dimension for every string.
例如
Dates = "12.02.2016, 13.08.2017, 19.05.2018"
Temperatures = "23.1, 24.9, 75.3"
Humidity = "26, 29, 95"
通过使用
AmbientConditionsArray = Split(Dates, ", ")
但是我真的不知道将其放入二维数组中
But I really have no idea to get it into a two dimensional array like
AmbientConditionsArray(0,0) = Date1
AmbientConditionsArray(0,1) = Temperature1
AmbientConditionsArray(0,2) = Humidity1
AmbientConditionsArray(1,0) = Date2
AmbientConditionsArray(1,1) = Temperature2
AmbientConditionsArray(1,2) = Humidity2
以此类推.
推荐答案
虽然您可以使用多维数组,但比较麻烦.
While you can use a multidimensional array, it will be comparatively cumbersome.
简单地使用三个单独的常规数组怎么样?
How about simply using three separate regular arrays?
Dates = Split("12.02.2016, 13.08.2017, 19.05.2018", ", ")
Temperatures = Split("23.1, 24.9, 75.3", ", ")
Humidity = Split("26, 29, 95", ", ")
要将它们作为一组值使用,我将使用字典.
to work with them as a block of values I would use a dictionary.
Dim AmbientConditions
Set AmbientConditions = CreateObject("Scripting.Dictionary")
AmbientConditions.Add "Dates", Split("12.02.2016, 13.08.2017, 19.05.2018", ", ")
AmbientConditions.Add "Temperatures", Split("23.1, 24.9, 75.3", ", ")
AmbientConditions.Add "Humidity", Split("26, 29, 95", ", ")
以后,您可以以可读的方式访问各个值:
Later you can access individual values in a readable manner:
MsgBox AmbientConditions("Humidity")(1)
' -> shows "29"
这篇关于多维数组vbscript中的多个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!