直到用逗号分隔值填充字符串

时间:2012-04-16 23:24:19

标签: vb.net arrays populate

嘿所有我想尝试填充这样的数组:

Dim tmpArray As String = ""

Do Until x = Form1.arrayCal.Length
    tmpArray = tmpArray & "," & x
    x += 1
Loop

tmpArray = Replace(tmpArray, ",1", "1")

Dim arrDaysInMonth As String() = {tmpArray}

Dim arrNumOfVisits As Double()= {10,20,30,40,50,52,20,20,10,35,3,8,47,7,2,5,55,8,0,0 ,6,55,0,2,12,0,0,21,14,0,3}

    Me.ChartControl1.Series.Clear()
    Dim s As New DataDynamics.ActiveReports.Chart.Series()

    s.Type = DataDynamics.ActiveReports.Chart.ChartType.Bar2D
    s.Points.DataBindXY(arrDaysInMonth, arrNumOfVisits)

然而,似乎我不能这样做..这样做似乎只把它放在一维数组而不是{1,2,3,4,5 ...}类型的数组因为它需要进入。

任何帮助都会很棒!

大卫

2 个答案:

答案 0 :(得分:1)

我认为你想要的就是这样:

    Dim daysCount As Integer = 31
    Dim arrDaysInMonth As String() = New String(daysCount - 1) {}

    For index As Integer = 0 To arrDaysInMonth.Length - 1
        arrDaysInMonth(index) = (index + 1).ToString()
    Next

    ' arrDaysInMonth(0) = "1"
    ' arrDaysInMonth(1) = "2"
    ' ...

或许你想要这个:

    Dim arrayCal As String = "1,2,3,4,5,6"
    Dim tmpArray As String() = arrayCal.Split(","c)

    ' tmpArray(0) = "1"
    ' tmpArray(1) = "2"
    ' ...

答案 1 :(得分:0)

如果你想动态创建数组,我建议不要使用数组,你应该使用集合,因为它们更快,并且它们节省了资源:

Dim array As New System.Collections.ArrayList

Do Until x = Form1.arrayCal.Length
   array.Add(x)
   x += 1
Loop

您还可以通过索引访问ArrayList的元素。

顺便说一句:您的版本无法运行,因为您需要编译并运行它正在运行的代码。

Dim arrDaysInMonth() As String = {"1,2,3"}

与此不一样

Dim arrDaysInMonth() As String = {"1","2","3"}