VB.NET - Array of strings in vb net - Asked By L K on 10-May-06 12:33 AM

Hi,
We are using an array of strings.
[CODE]

Dim Str1() as String  
...


Str1= Split(Source,",")
' Source is a String,that is declared  and populated with values in a different function
[/CODE]

The problem here is that the array Str1 retains its contents durings the next call of the function too ! 

Thus when it is filled with new values some of the old values remain!

eg.

First run:
----------
Source="2,3,4,6,"
Str1={"2","3","4","6"}

Next run:
-------------
Source="7,8,"
Str1={"7","8","4","6"}

-----whereas, it should be Str1={"7","8"}

-----------Any inputs on this issue??

Thanx :)
Asked By Shallu Gupta on 10-May-06 12:46 AM
Declare Array Local to the function.

ReDim - Asked By F Cali on 10-May-06 10:19 AM

Instead of the Dim, you can use ReDim to reinitialize your array:

ReDim Str1() as String
Str1= Split(Source,",")