5.9. Parse a Delimited Text File

Problem

You need to parse the contents of a delimited text file.

Solution

Create and configure a new Microsoft.VisualBasic.FileIO.TextFieldParser object that references the file you need to parse. Loop through the file until the EndOfData property is True. Use the ReadFields method to return an array of strings representing one row of parsed data from the file.

How It Works

The TextFieldParser class can be found in the Microsoft.VisualBasic.FileIO namespace. You can either use one of its constructors to create an instance directly or use the Shared My.Computer. FileSystem.OpenTextFieldParser method to return an instance. Some of the more important properties and methods of this class are listed in Table 5-7

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.