O'Reilly logo

Visual Basic 2008 Recipes: A Problem-Solution Approach by Rakesh Rajan, Matthew MacDonald, Allen Jones, Todd Herman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required