Click to See Complete Forum and Search --> : String to array


Rafale
September 28th, 2001, 07:16 AM
Hi !!!
Can someone help me to resolve this little problem ?

I got a string like:
Test = "alpha|beta|gamma;alpha1|beta1|gamma1;alpha2|beta2|gamma2;alpha3|beta3|gamma3;"

And I'like it to be in a two dimension array like:

arr=
alpha beta gamma
alpha1 beta1 gamma1
alpha2 beta2 gamma2
alpha3 beta3 gamma3

How can i easily do that ??

Thanks for your help...

Cakkie
September 28th, 2001, 07:31 AM
Well, there's no way to do that in one time, but we can do it like this:

private Sub Command1_Click()

Dim test as string
test = "alpha|beta|gamma;alpha1|beta1|gamma1;alpha2|beta2|gamma2;alpha3|beta3|gamma3;"

Dim tmpArr
Dim tmpArr2
Dim RealArr()

tmpArr = Split(test, ";")

ReDim RealArr(UBound(tmpArr), 3)

for t = 0 to UBound(tmpArr) - 1
tmpArr2 = Split(tmpArr(t), "|")
If Not (IsEmpty(tmpArr2)) then
for r = 0 to 2
RealArr(t, r) = tmpArr2(r)
next r
End If
next t

for t = 0 to UBound(RealArr)
Debug.print RealArr(t, 0) & " " & RealArr(t, 1) & " " & RealArr(t, 2)
next t

End Sub




Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Rafale
October 1st, 2001, 01:31 AM
Thx a lot for your Help!!!!!!!

Pierre-jean