Solved

I am using VS2010 with C# console application and was wondering how to write fixed length records to an output file based on an input file with text and binary data?

Posted on 2013-06-23
2
483 Views
Last Modified: 2013-07-12
How would you write 252 byte fixed length records to an output file using C# code in a console application with VS2010?
 
I am working with VS2010 and C#. I have an input file that has no file exension.
This file contains records of various types.
However, I am interested in extracting only 252 byte fixed length records from this file
that start with the sequence "51ELRC" in the first 6 positons of each record of this type.
Occurences of this record type can exist starting in any location within
the input file. How would you write C# code as a console application to extract all 252
byte records from this input file that start with the character sequence "51ELRC"
and write these record types to an output file titled output.txt as fixed record length records
of 252 bytes?

The input record layout is as follows for the records that have the value "51ELRC" in
starting positions 1 through 6.
The text fields are in ASCII format.
The records with the value type "51ELRC" in positions 1 through 6 are present throughtout
the input file in various locations within this file.

column         data type              positions
---------      -------------       ------------
Field 1        Text                 1  -   46
Field 2        Binary               47 -  118
Field 3        Text                 119
Field 4        Binary               120 - 132
Field 5        Text                 133 - 149
Field 6        Binary               150 - 162
Field 7        Text                 163 - 170
Field 8        Binary               171 - 183
Field 9        Text                 184 - 203
Field 10       Binary               204 - 216
Field 11       Text                 217 - 228
Field 12       Binary               229 - 241
Field 13       Text                 242 - 252
0
Comment
Question by:zimmer9
2 Comments
 
LVL 19

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 39271942
It would be helpful if you included a sample input file with the data you want extracted. I'm also not sure I understand the request overall. First off, is the input file larger than 252 bytes?

Basically, since it's binary and text data, I'd use a BinaryReader to read the file. Then, at each offset, if you want text, I'd convert the binary data to text with Convert.ToBase64String method.

Writing it out might be a bit of a challenge as you're attempting to mix text and binary information in a single file. I am not honestly sure how that would work out for the best You may simply want to keep the binary formatting for the output and have the binary representation of the text written out to the file and keep it in binary format.

Recommend this article:
http://stackoverflow.com/questions/4122153/how-to-write-some-text-as-bytes-without-encoding
0
 

Author Comment

by:zimmer9
ID: 39272150
I have attached an example file titled Sample that contains 3 detail records that have the value "51ELRC" in their first 6 positions for each record of this particular type. These record types are scattered throughout the file. My goal is to output all of the occurences of these record type "51ELRC"  records into an output file comprised of purely these records.

The records of type "51ELRC" are followed by the character string JJ*

So the output file would contain 252 byte records as follows where the ... represents
positions 7 through 242

51ELRC    ...          0000036934
51ELRC    ...          0000093745
51ELRC    ...          0000083846
sample
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now