EF BB BF prepended

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • guy

    EF BB BF prepended

    I have a routine that generates CSV files, the first character written is
    ControlChars.Qu ote
    this is done by means of System.IO.Strea mWriter.Write(C ontrolChars.Quo te)

    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
  • Jani Järvinen [MVP]

    #2
    Re: EF BB BF prepended

    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:



    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
    janij@removethi s.dystopia.fi



    Comment

    • Mattias Sjögren

      #3
      Re: EF BB BF prepended

      >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

      --
      Mattias Sjögren [C# MVP] mattias @ mvps.org
      http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
      Please reply only to the newsgroup.

      Comment

      Working...