Apologies, Apologies, Apologies, Apologies, Apologies, Apologies!!!!
There is nothing worse than some fool presenting the wrong question
and so wasting the time of those good people who come forward to help.
So here is the real problem -one line change to the original:
s(i)=new string(sTmp) 'and not as I put s(i)=new string(test)
Above line gives - error :
option strict on disallows implicit conversion string to 1-dim array
of char
Thanks for the solution Mark. There is a minor problem with it ie I
had to use Preserve to keep the existing array content. Btw why use -1
and not 0 in dim S(-1) as string as both create a first array entry ie
S(0) with value Nothing that can be populated.
So then (thanks to Mark) this the way to dynamically populate a string
array:
Option Strict On
Dim S() as String
Dim i as integer = -1
while we have got another new string in sTmp
i+=1
Redim Preserve S(i)
S(i) = sTmp
end while
Question : is this the "proper" way of doing this?
ReDim Preseve S(S.Length) should be used.
"Marc Butenko" <mb******@state.mt.us> wrote in message news:<eT**************@tk2msftngp13.phx.gbl>...
If I understand your question correctly, here is what you need to do:
Option Strict On
Dim S(-1) as String
Dim sTmp as String = "test"
Dim i as Integer = 0
Redim S(S.Length)
S(i) = sTmp
Redim S(S.Length)
i += 1
S(i) = "new String"
Hope that helps,
--
Marc Butenko
mb******@bresnan.net
"Zordiac" <zo*****@hotmail.com> wrote in message
news:77**************************@posting.google.c om... How do I dynamically populate a string array?
I hope there is something obvious that I'm missing here
Option Strict On
dim s() as string
dim sTmp as string = "test"
dim i as integer
s(i)=new string(test)
Above line gives - error implicit conversion string to 1-dim array of
char
Looked at stringbuilder and coverting to char array in contructor but
did not find an answer