Parsing comma delimited string into textboxes

Posted on 2004-11-15
Last Modified: 2010-04-24
How would I parse a comma delimited string into multiple text boxes on my form ie:

FirstName, LastName, Birthdate,
Ralph, Malph, 12/25/2004
Dim WholeBirthdate as String
Dim Birthdate1 as String
Dim Birthdate2 as String
Dim Birthdate3 as String

txtFirstName.Text = From Beginning to First Comma
txtLastName.Text = From First Comma to Second Comma
WholeBirthdate = From Second Comma to the end
   Take WholeBirthdate and break it into three parts at each "/"
     Birthdate1 = the first number
     Birthdate2 = the second number
     Birthdate3 = the third number

    txtBirthdate1.Text = Birthdate1
    txtBirthdate2.Text  = Birthdate2
    txtBirthdate3.Text  = Birthdate3

How could I do that in
Question by:Matrix1000
    LVL 27

    Expert Comment

    LVL 13

    Accepted Solution

    Dim myString As String = "FirstName, LastName, Birthdate,Ralph, Malph, 12/25/2004"

    Dim myArray() As String = Split(myString,",")

    txtFirstName.Text = myArray(0)
    txtLastName.Text = myArray(1)
    WholeBirthdate = myArray(2)

    Dim myArray2() As String = Split(myString(3),"/")

        txtBirthdate1.Text = myArray2(0)
        txtBirthdate2.Text  = myArray2(1)
        txtBirthdate3.Text  = myArray2(2)

    LVL 13

    Expert Comment

    The line Dim myString As String = "FirstName, LastName, Birthdate,Ralph, Malph, 12/25/2004"
    should have been

    Dim myString As String = "Ralph, Malph, 12/25/2004"

    LVL 13

    Expert Comment

    Oops another typing error......

    Dim myArray2() As String = Split(myString(3),"/")

    should have been

    Dim myArray2() As String = Split(myString(2),"/")

    Note that in my sample I have used split function to split your string......Here is the complete declaration of Split function

    Function Split(
       ByVal Expression As String,
       Optional ByVal Delimiter As String = " ",
       Optional ByVal Limit As Integer = -1,
       Optional ByVal Compare As CompareMethod = CompareMethod.Binary
    ) As String()


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now