No. To change the endianness, you need to understand the contents to know
where each cluster of bytes begins and ends - for example, if the file
contains 4 byes of Int32 "foo" and 2 bytes of Int16 "bar" - then without
prior knowledge you don't know how many bytes to reverse.
If you are just worrying about text files and UTF-16 then life is simpler -
you can simply read and write the file specifying the desired Encodings :
Encoding.Unicode and Encoding.BigEndianUnicode should do the job.
(note - you can of course change UTF-16 endianness more directly, but the
approach cited applies to all other encodings, where-as a direct byte swap
only works for encodings such as UTF-16; plus you don't need to worry about
the BOM etc)
Yes, assuming that your specified format is UTF-16. It should work
with any other available encoding that you care to name. For
reasonable-length files you can probably even get awasy with simply:
(and even the first line might be considered overkill, as it will
*usually* guess the incoming encoding)
Marc
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.