Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
492 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
[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
2 Comments
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

610 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