Home All Groups Group Topic Archive Search About

How can I write to a file with different encoding?

Author
23 Jan 2006 9:02 AM
Willy S
How can I write to the same file with different encoding?
The file has records where different fields in each record has different
encoding (because of use in different modules in a production machine).
Open and close several times (with different encoding) for each record is
not whery efficient.

Author
23 Jan 2006 9:28 AM
Vadym Stetsyak
You can open file once, and write to multiple positions.
You can write bytes that were obtained with special encoding, Lets suppose
that you have 2 fields with
UTF-8 and ASCII

Then you can obtain bytes with appropriate encoding
byte[] field1 = Encoding.ASCII.GetBytes(field1);
byte[] field2 = Encoding.UTF8.GetBytes(field2);

Now you get two fields encoded with 2 different encodings

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

Show quote
"Willy S" <Wil***@discussions.microsoft.com> wrote in message
news:2708141B-C50E-411E-8D78-9549AC6D4572@microsoft.com...
>
> How can I write to the same file with different encoding?
> The file has records where different fields in each record has different
> encoding (because of use in different modules in a production machine).
> Open and close several times (with different encoding) for each record is
> not whery efficient.
>
Author
25 Jan 2006 4:46 AM
Mihai N.
> The file has records where different fields in each record has different
> encoding (because of use in different modules in a production machine).
This is really-really bad internationalization design.
Go with a for of Unicode (UTF-8, UTF-16, whatever) and you will not be
mistaken.

--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email

AddThis Social Bookmark Button