What is OPML?
FW: [DOTNET-CX] Binary text file manipulation
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > .Net Development > FW: [DOTNET-CX] Binary text file manipulation 25 November 2004 03:08:29

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

FW: [DOTNET-CX] Binary text file manipulation

Richard Barker 25 November 2004 03:08:29
 Actually the problem is worse than I thought. The mainframe (HP3000) from
where I receive the files uses something called MPE/iX, the file does
contain a CR & LF before it is sent, yet when the file is sent as Binary the
CR & LF are replaced by a space.

I think the only thing I can do is read the file in and every 318 characters
write a line to a new file.

What's the best way in C# to do that.



-----Original Message-----
From: Paul Stevens [mailto:P­Stevens@MULTICHOICE.CO.ZA]
Sent: 24 November 2004 14:00
To: DOTNET-CX@DISCUSS.D­EVELOP.COM
Subject: Re: [DOTNET-CX] Binary text file manipulation


Unix uses only a carriage return so the linefeed character is missing doing
an ASCII ftp inserts the missing line feed character but sometimes destroys
other data, you should be able to get away with replacing all carriage
return characters with a carriage return & linefeed character.

-----Original Message-----
From: Discussion relating to the specifics of the C# and Managed C++
languages [mailto:D­OTNET-CX@DISCUSS.DEVELOP.COM] On Behalf Of Richard Barker
Sent: 24 November 2004 11:55 AM
To: DOTNET-CX@DISCUSS.D­EVELOP.COM
Subject: [DOTNET-CX] Binary text file manipulation

Hi


I am FTP'ing some fixed length ascii text files from an mainframe computer
to my windows box and importing them into an SQL data warehouse. The problem
I have is, if I use ascii as a transfer option, some of the European
characters disappear from the text. If I use the binary option, they appear
correctly, but the carriage returns and line feeds are, effectively,
missing, so the file is one big blob.

I need to restore the file, so each record length is 318 bytes.

What is the easiest way in C# to do this.








===================­===============
This message contains confidential information and is intended solely for
the use of the individual or entity to whom it is addressed. If you are not
the named addressee you should not disseminate, distribute or copy this
email. Please inform the sender immediately if you have received this e-mail
by mistake and delete this email from your system. Email transmission cannot
be guaranteed to be secure or error-free as information could be
intercepted, corrupted, lost, destroyed, arrive late or be incomplete. The
sender therefore does not accept liability for any errors or omissions in
the contents of this message, which arise as a result of email transmission.
If verification is required please request a hard copy version. No contracts
may be concluded on behalf of Virgin Express SA/NV by means of email
communication. Finally, the recipient should check this e-mail and any
attachments for the presence of viruses. The company accepts no liability
for any damage caused by any virus transmitted by this email.
===================­===============

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com
Some .NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at http://discuss.deve­lop.com

*******************­********************­********************­*****************
*******************­********************­*******
Everything in this e-mail and attachments relating to the official business
of MultiChoice Africa is proprietary to
the company. Any view or opinion expressed in this message may be the view
of the individual and should not automatically
be ascribed to the company. If you are not the intended recipient, you may
not peruse, use, disseminate, distribute or
copy this message. If you have received this message in error, please notify
the sender immediately by email, facsimile
or telephone and destroy the original message.
*******************­********************­********************­*****************
*******************­********************­*******

===================­================
This list is hosted by DevelopMentorВ® http://www.develop.­com
Some .NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at http://discuss.deve­lop.com

===================­===============
This message contains confidential information and is intended solely for
the use of the individual or entity to whom it is addressed. If you are not
the named addressee you should not disseminate, distribute or copy this
email. Please inform the sender immediately if you have received this e-mail
by mistake and delete this email from your system. Email transmission cannot
be guaranteed to be secure or error-free as information could be
intercepted, corrupted, lost, destroyed, arrive late or be incomplete. The
sender therefore does not accept liability for any errors or omissions in
the contents of this message, which arise as a result of email transmission.
If verification is required please request a hard copy version. No contracts
may be concluded on behalf of Virgin Express SA/NV by means of email
communication. Finally, the recipient should check this e-mail and any
attachments for the presence of viruses. The company accepts no liability
for any damage caused by any virus transmitted by this email.
===================­===============

===================­================
This list is hosted by DevelopMentorВ® http://www.develop.­com
Some .NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Adrian Martin 24 November 2004 17:13:17 permanent link ]
 Just use the substring method to rip the string up.

Sound like the Mainframes FTP could do with some tuning

Is FTP the only interface to its file system?


-----Original Message-----
From: Discussion relating to the specifics of the C# and Managed C++
languages [mailto:D­OTNET-CX@DISCUSS.DEVELOP.COM] On Behalf Of Richard
Barker
Sent: 24-November-2004 13:27
To: DOTNET-CX@DISCUSS.D­EVELOP.COM
Subject: [DOTNET-CX] FW: [DOTNET-CX] Binary text file manipulation

Actually the problem is worse than I thought. The mainframe (HP3000)
from where I receive the files uses something called MPE/iX, the file
does contain a CR & LF before it is sent, yet when the file is sent as
Binary the CR & LF are replaced by a space.

I think the only thing I can do is read the file in and every 318
characters write a line to a new file.

What's the best way in C# to do that.



-----Original Message-----
From: Paul Stevens [mailto:P­Stevens@MULTICHOICE.CO.ZA]
Sent: 24 November 2004 14:00
To: DOTNET-CX@DISCUSS.D­EVELOP.COM
Subject: Re: [DOTNET-CX] Binary text file manipulation


Unix uses only a carriage return so the linefeed character is missing
doing an ASCII ftp inserts the missing line feed character but sometimes
destroys other data, you should be able to get away with replacing all
carriage return characters with a carriage return & linefeed character.

-----Original Message-----
From: Discussion relating to the specifics of the C# and Managed C++
languages [mailto:D­OTNET-CX@DISCUSS.DEVELOP.COM] On Behalf Of Richard
Barker
Sent: 24 November 2004 11:55 AM
To: DOTNET-CX@DISCUSS.D­EVELOP.COM
Subject: [DOTNET-CX] Binary text file manipulation

Hi


I am FTP'ing some fixed length ascii text files from an mainframe
computer to my windows box and importing them into an SQL data
warehouse. The problem I have is, if I use ascii as a transfer option,
some of the European characters disappear from the text. If I use the
binary option, they appear correctly, but the carriage returns and line
feeds are, effectively, missing, so the file is one big blob.

I need to restore the file, so each record length is 318 bytes.

What is the easiest way in C# to do this.








===================­===============
This message contains confidential information and is intended solely
for the use of the individual or entity to whom it is addressed. If you
are not the named addressee you should not disseminate, distribute or
copy this email. Please inform the sender immediately if you have
received this e-mail by mistake and delete this email from your system.
Email transmission cannot be guaranteed to be secure or error-free as
information could be intercepted, corrupted, lost, destroyed, arrive
late or be incomplete. The sender therefore does not accept liability
for any errors or omissions in the contents of this message, which arise
as a result of email transmission.
If verification is required please request a hard copy version. No
contracts may be concluded on behalf of Virgin Express SA/NV by means of
email communication. Finally, the recipient should check this e-mail and
any attachments for the presence of viruses. The company accepts no
liability for any damage caused by any virus transmitted by this email.
===================­===============

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com Some
.NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

*******************­********************­********************­*************
****
*******************­********************­*******
Everything in this e-mail and attachments relating to the official
business of MultiChoice Africa is proprietary to the company. Any view
or opinion expressed in this message may be the view of the individual
and should not automatically be ascribed to the company. If you are not
the intended recipient, you may not peruse, use, disseminate, distribute
or copy this message. If you have received this message in error, please
notify the sender immediately by email, facsimile or telephone and
destroy the original message.
*******************­********************­********************­*************
****
*******************­********************­*******

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com Some
.NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­===============
This message contains confidential information and is intended solely
for the use of the individual or entity to whom it is addressed. If you
are not the named addressee you should not disseminate, distribute or
copy this email. Please inform the sender immediately if you have
received this e-mail by mistake and delete this email from your system.
Email transmission cannot be guaranteed to be secure or error-free as
information could be intercepted, corrupted, lost, destroyed, arrive
late or be incomplete. The sender therefore does not accept liability
for any errors or omissions in the contents of this message, which arise
as a result of email transmission.
If verification is required please request a hard copy version. No
contracts may be concluded on behalf of Virgin Express SA/NV by means of
email communication. Finally, the recipient should check this e-mail and
any attachments for the presence of viruses. The company accepts no
liability for any damage caused by any virus transmitted by this email.
===================­===============

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com Some
.NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at
http://discuss.deve­lop.com




Opinions expressed in this e-mail are those of the writer and not the company. E-mail traffic is monitored within Johnston Press and messages may be viewed. This e-mail and any files with it are solely for the use of the addressee(s). If you are not the intended recipient, you have received this e-mail in error. Please delete it or return it to the sender or notify us by email at postmaster@jpress.c­o.uk

===================­================
This list is hosted by DevelopMentor http://www.develop.­com
Some .NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Ryan Heath 24 November 2004 18:30:49 permanent link ]
 Hi Richard,

Try this, should be the fastest way...

using ( FileStream inFs = new FileStream( "aaa", FileMode.Open))
using ( FileStream outFs = new FileStream( "bbb", FileMode.CreateNew)­)
{
byte[] bytes = new byte[318];
byte[] cr = new byte[] { 13, 10 };

int bytesRead = inFs.Read( bytes, 0, bytes.Length);
while ( bytesRead != 0)
{
inFs.Write( bytes, 0, bytesRead);
inFs.Write( cr, 0, cr.Length);
bytesRead = inFs.Read( bytes, 0, bytes.Length);
}
}

HTH
// Ryan

===================­================
This list is hosted by DevelopMentor http://www.develop.­com
Some .NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Jon Skeet 24 November 2004 18:34:28 permanent link ]
 Richard Barker wrote:> Actually the problem is worse than I thought. The mainframe (HP3000) from> where I receive the files uses something called MPE/iX, the file does> contain a CR & LF before it is sent, yet when the file is sent as Binary the> CR & LF are replaced by a space.>
I think the only thing I can do is read the file in and every 318 characters> write a line to a new file.>
What's the best way in C# to do that.

Are you sure that it's not just an encoding problem? If you look at the
file in a binary file editor, does it look the same as the original?

Jon

===================­================
This list is hosted by DevelopMentorВ® http://www.develop.­com
Some .NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Stoyan Damov 24 November 2004 19:08:18 permanent link ]
 
inFs.Write( bytes, 0, bytesRead);>> inFs.Write( cr, 0, cr.Length);

s/inFs/outFS/ :)­

Cheers,
Stoyan

-----Original Message-----
From: Discussion relating to the specifics of the C# and Managed C++
languages [mailto:D­OTNET-CX@DISCUSS.DEVELOP.COM] On Behalf Of Ryan Heath
Sent: Wednesday, November 24, 2004 5:31 PM
To: DOTNET-CX@DISCUSS.D­EVELOP.COM
Subject: Re: [DOTNET-CX] FW: [DOTNET-CX] Binary text file manipulation


Hi Richard,

Try this, should be the fastest way...

using ( FileStream inFs = new FileStream( "aaa", FileMode.Open)) using (
FileStream outFs = new FileStream( "bbb", FileMode.CreateNew)­) {
byte[] bytes = new byte[318];
byte[] cr = new byte[] { 13, 10 };

int bytesRead = inFs.Read( bytes, 0, bytes.Length);
while ( bytesRead != 0)
{
inFs.Write( bytes, 0, bytesRead);
inFs.Write( cr, 0, cr.Length);
bytesRead = inFs.Read( bytes, 0, bytes.Length);
}
}

HTH
// Ryan

===================­================
This list is hosted by DevelopMentorR http://www.develop.­com Some .NET
courses you may be interested in:

Programming C#
November 15-19, in Los Angeles http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor http://www.develop.­com
Some .NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Richard Barker 24 November 2004 20:11:59 permanent link ]
 Excellent

Thanks, that solved my problem.

-----Original Message-----
From: Ryan Heath [mailto:ryan.q.heath@GMAIL.COM]
Sent: 24 November 2004 16:31
To: DOTNET-CX@DISCUSS.D­EVELOP.COM
Subject: Re: [DOTNET-CX] FW: [DOTNET-CX] Binary text file manipulation


Hi Richard,

Try this, should be the fastest way...

using ( FileStream inFs = new FileStream( "aaa", FileMode.Open))
using ( FileStream outFs = new FileStream( "bbb", FileMode.CreateNew)­)
{
byte[] bytes = new byte[318];
byte[] cr = new byte[] { 13, 10 };

int bytesRead = inFs.Read( bytes, 0, bytes.Length);
while ( bytesRead != 0)
{
inFs.Write( bytes, 0, bytesRead);
inFs.Write( cr, 0, cr.Length);
bytesRead = inFs.Read( bytes, 0, bytes.Length);
}
}

HTH
// Ryan

===================­================
This list is hosted by DevelopMentorВ® http://www.develop.­com
Some .NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at http://discuss.deve­lop.com

===================­===============
This message contains confidential information and is intended solely for
the use of the individual or entity to whom it is addressed. If you are not
the named addressee you should not disseminate, distribute or copy this
email. Please inform the sender immediately if you have received this e-mail
by mistake and delete this email from your system. Email transmission cannot
be guaranteed to be secure or error-free as information could be
intercepted, corrupted, lost, destroyed, arrive late or be incomplete. The
sender therefore does not accept liability for any errors or omissions in
the contents of this message, which arise as a result of email transmission.
If verification is required please request a hard copy version. No contracts
may be concluded on behalf of Virgin Express SA/NV by means of email
communication. Finally, the recipient should check this e-mail and any
attachments for the presence of viruses. The company accepts no liability
for any damage caused by any virus transmitted by this email.
===================­===============

===================­================
This list is hosted by DevelopMentorВ® http://www.develop.­com
Some .NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Ryan Heath 24 November 2004 20:41:35 permanent link ]
 Stoyan Damov wrote:>> inFs.Write( bytes, 0, bytesRead);>> inFs.Write( cr, 0, cr.Length);>
s/inFs/outFS/ :)­

Warrant 'til the front-door, as we say in the low lands ... ;)

// Ryan

===================­================
This list is hosted by DevelopMentor http://www.develop.­com
Some .NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Kenneth Lee 25 November 2004 03:08:29 permanent link ]
 In a message dated 11/24/04 7:32:55 AM Pacific Standard Time,
ryan.q.heath@GMAIL.­COM writes:

using ( FileStream inFs = new FileStream( "aaa", FileMode.Open))> using ( FileStream outFs = new FileStream( "bbb", FileMode.CreateNew)­)> {> byte[] bytes = new byte[318];> byte[] cr = new byte[] { 13, 10 };>
int bytesRead = inFs.Read( bytes, 0, bytes.Length);> while ( bytesRead != 0)> {> inFs.Write( bytes, 0, bytesRead);> inFs.Write( cr, 0, cr.Length);> bytesRead = inFs.Read( bytes, 0, bytes.Length);> }> }>

Now I have a question. If the record length is 318 and the CR/LF was
converted to a single space, why wasn't the bytes length 319 and in the loop have an
"if (bytesRead==319)--b­ytesRead;" statement in it? Was the record length
really 317 and a space is now tacked on the end of the new file?

===================­================
This list is hosted by DevelopMentor http://www.develop.­com
Some .NET courses you may be interested in:

Programming C#
November 15-19, in Los Angeles
http://www.develop.­com/courses/csharp

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > .Net Development > FW: [DOTNET-CX] Binary text file manipulation 25 November 2004 03:08:29

see also:
1:M table mapped relations
Specifiying a value-object package
webwork javadoc tag ??
пройди тесты:
see also:
Borland C++ Builder 6.0
Hyperlinks to files on CD

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .