Re: How do I avoid writing the Byte Order Mark ?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On 20 Ago, 20:29, Kelly Ethridge <ke...@xxxxxxxxxxxxxxxxx> wrote:
pamela fluente wrote:
On 20 Ago, 17:36, Kelly Ethridge <ke...@xxxxxxxxxxxxxxxxx> wrote:
pamela fluente wrote:
On 20 Ago, 16:52, Göran Andersson <gu...@xxxxxxxxx> wrote:
pamela fluente wrote:
I am writing some text using something like:
Using FileStream As New FileStream(FileName, FileMode.Create)
Using StreamWriter As New StreamWriter(FileStream,
System.Text.Encoding.UTF8)
Try
StreamWriter.Write(Text)
FileStream.Flush()
...
QUESTION: How do I avoid writing the Byte Order Mark ?
It's for HTML pages: validator is complaining about the mark.
Then the problem is not the writing of the file, but the reading of the
file. When the file the read, the BOM is not part of the file data.
If you read the file as a binary file instead of a text file, you don't
get an encoded string, you get a binary image of a unicode file.
As I explained the file is read by browsers (it's a web page).
The validator message is:
Byte-Order Mark found in UTF-8 File.
The Unicode Byte-Order Mark (BOM) in UTF-8 encoded files is known to
cause problems for some text editors and older browsers. You may want
to consider avoiding its use until it is better supported.
I am looking for a way NOT to write the BOM, because the validator
complains.
How do avoid the BOM writing ?
-P
The default UTF8 encoding is set to write the preamble (BOM). Instead of
using System.Text.Encoding.UTF8, you should create a new UTF8Encoding
object. By default, a new one won't include the the preamble (BOM).- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -

If this is true, it is a simple solution.

I will try that. I am wondering why a new object would behave
differently (?)

-P

Well, one of the constructors for the UTF8Encoding class allows you to
include a BOM or not. If you use the default constructor then the
default is to not include the BOM.- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -

Thanks! That works fine.


-P

.



Relevant Pages

  • Re: How do I avoid writing the Byte Order Mark ?
    ... How do I avoid writing the Byte Order Mark? ... the BOM is not part of the file data. ... The Unicode Byte-Order Mark in UTF-8 encoded files is known to ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How do I avoid writing the Byte Order Mark ?
    ... How do I avoid writing the Byte Order Mark? ... the BOM is not part of the file data. ... The Unicode Byte-Order Mark in UTF-8 encoded files is known to ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How do I avoid writing the Byte Order Mark ?
    ... How do I avoid writing the Byte Order Mark? ... validator is complaining about the mark. ... the BOM is not part of the file data. ... a new one won't include the the preamble.- Nascondi testo tra virgolette - ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Compassionare Conservatism
    ... You know civilisation is in serious trouble when this sort of writing ... "Almost all intellectuals profess to love ... humanity and to be working for its improvement and happiness. ... Just out of curiosity, what would you do regarding conservative/right-leaning publications, Mark, since you think that "civilisation is in serious trouble when this sort of writing starts to ...
    (alt.usage.english)
  • Re: How do... YOU... do... "IT"?
    ... Which starts with about half a dozen scene headings, ... >point is very much 'blank page, start writing, see where we ... I draw a large circle and mark off the quarter hours. ... It works quite well to have key turning points around the quarter mark ...
    (rec.arts.sf.composition)