How to Parse a "," delimited file?

Posted on 2004-11-23
Last Modified: 2010-04-23
I have a .txt file I have to parse but I'm not sure how to do it.
It is delimited in such a way that it puts "" around data thats there yet when there is no data it just places a comma like this ...


How could I parse that into an array so that I can call each piece individually and use them to fill out a form?
Question by:Matrix1000
    LVL 27

    Assisted Solution

    dim data as string  = "FirstName","LastName",,,,"FavoriteColor"
     Dim dataArray() As String

            ' Message parts are divided by ","  Break the string into an array accordingly.
            dataArray = data.Split(Chr(44))

    FIRSTNAME =dataArray(0)

    AND SO ON..........
    LVL 85

    Accepted Solution

    Just use the code I gave you before but remove all the quotation marks before splitting it:

            Dim fileName As String = "C:\someFile.txt"
            If Not File.Exists(fileName) Then
                MsgBox(fileName, MsgBoxStyle.Critical, "File Not Found")
                Exit Sub
            End If

            Dim sr As StreamReader = New StreamReader(fileName)
            Dim inputLine As String = sr.ReadLine
            If Not (inputLine Is Nothing) Then
                inputLine = Replace(inputLine, Chr(34), "")  '               <-----   remove all quotation marks
                Dim values() As String = Split(inputLine, ",")
                .Document.Frames("Main").document.Forms(0)("app_first_name").Value = values(0)
                .Document.Frames("Main").document.Forms(0)("app_last_name").Value = values(1)
                ' etc...
            End If

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Access - Multiple SQl statements 12 54
    Linq Unique list ? 3 30
    Better way of writing the code 4 22
    Merging PDFs with VB.NET 10 11
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    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

    9 Experts available now in Live!

    Get 1:1 Help Now