开发者

VB.NET: How to incrementally replace values in String Array

I have a String array with the following values:

dim strArray() as string  
dim newValueFor0Index as string = "Z"  
strArray(0) = "A"  
strArray(1) = "B"  
strArray(2) = "C"`

what i need is a loop or something to replace the values as such:

strArr开发者_如何学Goay(0) = "Z"  
strArray(1) = "A"  
strArray(2) = "B"`

I then need to add another index to the strArray() which will hold the last value ie:

strArray(0) = "Z"  
strArray(1) = "A"  
strArray(2) = "B"  
strArray(3) = "C"`

I tried a while loop :

while i < Count

    ni++  
    currentArr(ni) = currentArr(i)  
    i++  
end while  

but this won't work because i am using redundant values


An array is simply the wrong collection type to do this. It is trivial with a list:

    Dim lst As New List(Of String)
    lst.Add("A")
    lst.Add("B")
    lst.Add("C")
    lst.Insert(0, "Z")

You can always whack it back to an array, if really necessary:

    Dim array() As String = lst.ToArray()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜