Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

How to Parse a "," delimited file?

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

FIRSTNAME,LASTNAME,BIRTHDAY,SS#,DOGSNAME,FAVORITECOLOR,
"FirstName","LastName",,,,"FavoriteColor",

How could I parse that into an array so that I can call each piece individually and use them to fill out a form?
0
Matrix1000
Asked:
Matrix1000
2 Solutions
 
planoczCommented:
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)
LASTNAME=dataArray(1)
BIRTHDAY=dataArray(2)
SS#=dataArray(3)
DOGSNAME=dataArray(4)
FAVORITECOLOR=dataArray(5)

AND SO ON..........
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
        sr.Close()
        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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now