EF BB BF prepended

G

Guest

I have a routine that generates CSV files, the first character written is
ControlChars.Quote
this is done by means of System.IO.StreamWriter.Write(ControlChars.Quote)

and normally works correctly.

however if a large file (approx 14Mb) is generated the hex values as seen
with the Binary Editor EF BB BF appear immediately before the Quote character
(hex 22)

any idea what causes this / how to prevent it?

guy
 
J

Jani Järvinen [MVP]

Hi,
however if a large file (approx 14Mb) is generated the hex values as seen
with the Binary Editor EF BB BF appear immediately before the Quote
character
(hex 22)

The three bytes are a so-called Byte Order Mark (BOM), which is used in
Unicode files:

http://en.wikipedia.org/wiki/Byte_Order_Mark

In this case, EF BB BF means the file is a UTF-8 encoded file.
any idea what causes this / how to prevent it?

When you construct your StreamWriter class, you can specify the encoding you
want to use. For example, you could use the ASCII encoding, however this can
(will) cause problems if you write characters to your file that are not part
of the original ASCII table. As such, UTF-8 is a safe choice at least in the
Western world.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 
M

Mattias Sjögren

any idea what causes this / how to prevent it?
When you construct your StreamWriter class, you can specify the encoding you
want to use. For example, you could use the ASCII encoding, however this can
(will) cause problems if you write characters to your file that are not part
of the original ASCII table. As such, UTF-8 is a safe choice at least in the
Western world.

You can also create a new instance of UTF8Encoding, specify that it
shouldn't emit a BOM, and pass it to the SteamWriter.


Mattias
 

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