The Problem Solver

Tell me and I will forget
Show me and I will remember
Involve me and I will understand
- Confucius -

Google Ads

This Blog

Syndication

Search

Tags

News





  • View Maurice De Beijer's profile on LinkedIn

Community

Email Notifications

Explore

Archives

Need to read comma separated text files?

Then you really need to take a look at the TextFieldParser class. And if you never run into it that might be because it is tucked away in the Microsoft.VisualBasic.FileIO namespace, not exactly the first place I tend to start looking. But it parses either delimited or fixed with files. It has loads of options like setting the delimiter characters or specifying whether the data is enclosed in quotes or not. A real useful class to gave lying around given the number of questions I hear about reading CSV type files.

And yes C# diehards out there, just add a reference to Microsoft.VisualBasic.dll and you can use the type just as well Smile

Enjoy!

Published Thu, May 24 2007 17:24 by Maurice
Filed under: ,

Comments

# re: Need to read comma separated text files?@ Wednesday, May 30, 2007 1:40 AM

Don't you know what is the reason that TextFieldParser lives in Microsoft.VisualBasic.FileIO, but not somewhere in common namespaces? I wouldn't have had to write my own if I knew where to find it :)

by Oleksandr Pav.

# re: Need to read comma separated text files?@ Wednesday, May 30, 2007 3:11 AM

Well my guess is that it all comes down to ownership if namespaces. I know the Membership or Caching API's that lives in System.Web is just as useful in a WinForms application. However it was developed by the ASP.NET team and they had to put it in the Syetm.Web namespace. My guess is the same happened here where the VB team created a very useful class and didn't have permission to put it in System.IO where it really should be.

Just my guess though and there could very well be other reasons I am unaware of.

by Maurice

# re: Need to read comma separated text files?@ Monday, July 23, 2007 6:24 PM

Hi,

If i want to find out the total number of lines a csv file has before i create the string array to store the content, what can i do to achieve it?

by Jason Shim

# re: Need to read comma separated text files?@ Monday, August 13, 2007 2:03 AM

Hi Jason,

Sorry for the delay but I just got back from my vacation.

The only way would be to read the file and count the number of lines. Sort of means reading the file twice though.

by Maurice

# Apply Online For a Credit Cards@ Saturday, June 13, 2009 11:30 AM

The best information i have found exactly here. Keep going Thank you