Solved

import fixed width text file

Posted on 2011-03-14
5
957 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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