New Framework: UTF-8 TextOutputStream saved without BOM

Hi,

i noticed during analyzing my created Textfiles, I done with the new Framework, in a Hex Editor („Hex Friend“), they don’t have a Byte Order Mark. How can I add? Found this code snippet for the classic Framework:

t.Write Encodings.UTF8.Chr(&hEFBBBF)

You can use this code:

[code]Dim f As Xojo.IO.FolderItem = Xojo.IO.SpecialFolder.Documents.Child(“SaveData.txt”)

Dim output As Xojo.IO.TextOutputStream = Xojo.IO.TextOutputStream.Create(f, Xojo.Core.TextEncoding.UTF8)
output.Write text.FromUnicodeCodepoint(&hFEFF)
output.WriteLine(“This text is appended to the end of the file.”)
output.Close[/code]

So you write &hFEFF and depending on text encoding, you get the bytes for UTF-16, UTF-8 or whatever.

Wow, that’s a nice snippet. Like magic, one codepoint which automatically writes the Byte Order Mark depending on Xojo.Core.TextEncoding
Thanks Christian :slight_smile: