CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: String to array

  1. #1
    Join Date
    Jun 2001
    Posts
    5

    String to array

    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...


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: String to array

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Jun 2001
    Posts
    5

    Re: String to array

    Thx a lot for your Help!!!!!!!

    Pierre-jean


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured