Results 1 to 8 of 8

Thread: String Data Parser

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    7

    Exclamation String Data Parser

    i am trying to make a simple program which will take a string with information "Name, age; Name, age; " and so on and will move it into an array of a data structure called Person (containing Name, age) any idea of how a loop that does that would look like?

  2. #2
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Dim Person() as String

    Person = Split("George, 20; Frank, 99;Egads, 9999898",";")


    puts the string into the array, as you said.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    7
    what i meant is that person is a data structure such as this:
    Public Structure Person
    Dim Name as String
    Dim Age as integer

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    7
    what i meant is that person is a data structure such as this:
    Public Structure Person
    Dim Name as String
    Dim Age as integer
    end structure

  5. #5
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    there's no such thing. do you mean UDT?

    Private Type Person
    Name as String
    Age as Integer
    End Type
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    7
    well yeah ( itz just thats the way it iz on .Net)

  7. #7
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    VB Code:
    1. Private Type Person
    2.     Name As String
    3.     Age As Integer
    4. End Type
    5.  
    6. Option Explicit
    7. Private Sub Form_Load()
    8. Dim Persons() As Person
    9. Dim Temp() As String
    10. Dim Temp2() As String
    11. Dim i As Long
    12. Temp = Split("George,20; Frank,99;Egads,9999898", ";")
    13.  
    14. For i = LBound(Temp) To UBound(Temp)
    15.     Temp2 = Split(Temp(i), ",")
    16.     On Error Resume Next
    17.     ReDim Preserve Persons(UBound(Persons) + 1)
    18.     If Err Then ReDim Preserve Persons(0)
    19.    
    20.     Persons(UBound(Persons)).Name = Temp2(0)
    21.     Persons(UBound(Persons)).Age = Temp2(1)
    22. Next i
    23.  
    24.  
    25. MsgBox Persons(1).Name
    26. End Sub
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    7
    Thank you

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