Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextFieldParser problem with field data ending with quote period

Status
Not open for further replies.

bakershawnm

Programmer
Apr 18, 2007
84
US
hello all,

I am using TextFieldParser to parse through a text file looking for small snippets of information. Large file, lots of useless data. But it has the advantage that since it is intended to be a printed file it has unique delimiters (vertical bar) for columns and page edges. Makes using the TextFieldParser very easy.

Well the problem is in some of the useless information I could have a comment that ends with a ". instead of the ." like it should. TextFieldParser then throws a MalformedLineException and causes my program to halt processing of the file and continue on to push the data it has into the database.

I really don't care about the data on any lines that would have that on them so what I am looking for is what is the best way to skip reading that line and continue on with the file?

I catch the exception (see below) and thought about changing the delimiter to nothing and setting it to not delimited and reading the line then setting it back to delimited. However not sure that would be the best way or if it would even work (since I have not tired it yet).

Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox(ex.Message & " - Malformed line exception.")

MSDN documentation is sorely lacking (as usual) on these kinds of things and I have not been able to find anything else on the subject.

Any help is (as always) appreciated.
shawn
 
Also forgot to mention I have HasFieldsEnclosedInQuotes set to True
 
Unless someone comes up with a better way of doing it this is what I settled on. I moved my Try Catch inward to each place it reads fields instead of having it over the whole section of code:

Try
instring = MyReader.ReadFields
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
' MsgBox(ex.Message & " - Reading line with ReadLine and moving on.")
instring(0) = MyReader.ReadLine()
End Try


it works but I guess I was looking for something a little more elegant. :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top