Solved

import fixed width text file

Posted on 2011-03-14
5
956 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

696 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