Solved

import fixed width text file

Posted on 2011-03-14
5
954 Views
Last Modified: 2012-05-11
Hi,
What is the best way to process a fixed width text file?
I have about 8 columns and need to read row by row. Using a stream reader or is it possible to read it into a dataset?
0
Comment
Question by:CraigLazar
5 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 63 total points
ID: 35125838
I think you would need to read it via a stream reader.  You could create an in memory dataset and populate that if your processing of the file contents is better suited to that.
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 63 total points
ID: 35126586
You've tagged this question in VB and C#, so not sure which you are using. If it is VB then this might be an alternative to manually parsing each line:

    http://msdn.microsoft.com/en-us/library/zezabash.aspx
0
 
LVL 11

Assisted Solution

by:Kusala Wijayasena
Kusala Wijayasena earned 62 total points
ID: 35127461
Hi Craig,

StreamReader with adjusted buffer size will improve your performance by requiring minimal memory foot print. On the other hand, if you load your data into dataset, it will take much bigger memory allocation (as same size of the physical file).

So if your requirement is to process line by line, then go for StreamReader. Or else, if you required all the records available in memory at the point of processing, dataset would be the option to follow

-Kusala
0
 
LVL 12

Assisted Solution

by:Mohamed Abowarda
Mohamed Abowarda earned 62 total points
ID: 35129079
If you are trying to split text file to string array (each array item will contain one line) you can use StringReader, TextReader or StreamReader to read the file in the variable "fileContents" and use the following code:
Dim strArray() As String = Split(fileContents, vbNewLine)

Open in new window

0
 
LVL 4

Author Closing Comment

by:CraigLazar
ID: 35144024
Hi Guys,
thanks for the input, all helped
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question