We help IT Professionals succeed at work.
Get Started

Reading from textfile where vbcrlf is a line delimiter as well as embedded within the data

Last Modified: 2012-05-09

I need urgent help reading from a textfile with vbcrlf for the row delimiter (end of line), however, the vbcrlf  can sometimes be in the data within the row. This causes the reader to think it has encountered a new row even though it is still has now finished reading/parsing the full row.

 I am using a pipe sysmbol "|"  as a column delimiter. There are 51 columns in each row.

Any ideas?

The simplest would be is to use a combo delimiter of vbcrlf and "|" to see if it has really reached the end of the row (this does not seem possible to do).

Another thing is to make sure that the 51 columns are parsed for each row/line even if the vbcrlf is encountered before the row is read/parsed to the end. However, I do not know how to do this. Concrete code example needed...

I need urgent help on this. Please see my code for details.

Many thanks.
Dim ZipToUnpack As String = fullzippath
        Dim TargetDir As String = Server.MapPath("uploads/")
        Dim ez As ZipEntry

        Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
            ' based on entry name, size, date, etc.   
            For Each ez In zip1
                ez.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)

                ' Once extracted, let us know
                dvResults.InnerHtml &= "<br />File <b>" & ez.FileName & "</b> has been extracted and uploaded." ' & TargetDir

                ' Open the file, using a streamreader
                Dim objSR As StreamReader = File.OpenText(TargetDir & ez.FileName)

                ' Read the file's contents into a variable
                Dim contents As String = objSR.ReadToEnd()

                ' Start: write Biodata CROSSREF to table
                If ez.FileName.Contains("Cross") Then

                    ' the array of rows
                    Dim arrRows() As String = contents.Split(vbCrLf) 'contents.Split("|" + vbCrLf)
                    Dim arrCells() As String

                    ' Loop through its contents
                    For Each a As Object In arrRows

                        Dim tbl As New Object
                        tbl = New tblBiodata_Cross_Reference_TEMP
                        dcMeheret.ExecuteCommand("Truncate table tblBiodata_Cross_Reference_TEMP")

                        ' If a line doesn't have |, then skip it
                        If a.Contains("GUID") Then Continue For

                        ' Split each row into the 3 columns
                        arrCells = a.Split("|")

                        ' Add each cell into the linq table row
                        With tbl
                            .Row = arrCells(0)
                            .Case_GUIDFrom = New Guid(arrCells(1))
                            .FullCaseNoFrom = arrCells(2)
                        End With

                End If
                ' End: write Biodata CROSSREF to table
                ' *** End: write biotable to respective tables. ***

                ' Close the streamreader


            ' Save changes

    End Sub

Open in new window

Watch Question
Test your restores, not your backups...
Expert of the Year 2019
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE