How to read quote-delimited file?

aman_VB

Member
Joined
Apr 27, 2010
Messages
23
Programming Experience
1-3
Hello VB experts. I am new to this and I was trying to read Quote-delimited file using VB TextFieldParser. It doesn't work. However it seems to work if I set the delimiter as comma (","). How do I read quote delimited file?

Thanks in advance.
Aman
=============================

Imports System.IO

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\test.txt")

'Specify that reading from a Quote-delimited file'
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(ControlChars.Quote) '<--doesn't work
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
For Each currentField In currentRow
TextBox1.Text = currentField
Next
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
End While
End Using
End Sub
End Class
 
VB.NET:
MyReader.HasFieldsEnclosedInQuotes = False

You should have got an error message stating that the double quote was an illegal delimiter when this is set to True (default).
 
Back
Top