import fixed width text file

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?
LVL 4
CraigLazarAsked:
Who is Participating?
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
Kusala WijayasenaSoftware EngineerCommented:
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
 
Mohamed AbowardaSoftware EngineerCommented:
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
 
CraigLazarAuthor Commented:
Hi Guys,
thanks for the input, all helped
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.