Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB - Append to array?

this is probably a super simple question. But I have this Array that I need to strip useless parts from. But I still want it in an array.

So, the array looks like this when it comes in:

ArrValues(0) "Firstname=FIRSTNAME"
ArrValues(1) "Lastname=LASTNAME"
ArrValues(2) "Username=USERNAME"
ArrValues(3) "Displayname=DISPLAYNAME"

Then I send this array through this code snippet:

For Each s In arrValues
    s = Split(s, "=")
    s = s(1)
Next

This strips the strings so I get only FIRSTNAME and so on. But, I want to send each cleaned string into an array again. How do I do that?

like image 931
Kenny Bones Avatar asked Mar 29 '11 12:03

Kenny Bones


1 Answers

To write back to the array, you need to use the ArrValues(index) = new_value notation. So, you need to use a regular For loop instead of For Each, and access the array elements by their indexes. Here's how you can do this:

For i = LBound(ArrValues) To UBound(ArrValues)
 s = ArrValues(i)
 s = Split(s, "=")
 ArrValues(i) = s(1)
Next
like image 116
Helen Avatar answered Oct 25 '22 05:10

Helen