How can I write to a file with different encoding?

G

Guest

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.
 
V

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
 
M

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top