October 23, 2019, 02:03:30 AM

Author Topic: Convert WriteStream into UTF8?  (Read 220 times)

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 247
  • No.
Convert WriteStream into UTF8?
« on: May 16, 2019, 01:52:21 PM »

Code: [Select]
Global TotalGlyphs:Int = 65535 'Total ASCII
Global OnGlyph:Int = 0
Global File:TStream

CreateFile("Glyphs.txt")
File = OpenStream("Glyphs.txt", False, True)

Repeat
WriteLine(File, Chr(OnGlyph))
OnGlyph = OnGlyph + 1
'Print Asc("무")
Until OnGlyph = TotalGlyphs

CloseStream(File)

This little snippit prints out every ASCII character, however incorrectly.   Around the 23k mark, characters will repeat themselves simply because the stream is writing to ANSI format.  Can i get the stream to output as UTF8, so that all the glyphs are properly written?

Offline TomToad

  • Sr. Member
  • ****
  • Posts: 440
Re: Convert WriteStream into UTF8?
« Reply #1 on: May 16, 2019, 03:56:42 PM »
The glyphs are being properly written in 16 bit unicode.  Most likely, the program you are opening up the resulting file in is expecting UTF-8.  If you want to output UTF-8, you can use a TextStream and specify UTF8 in the format.
Code: [Select]
SuperStrict
Local Stream:TStream = WriteStream("utf8::MyFile.txt")
For Local i:Int = 0 To 65535
WriteLine(Stream,Chr(i))
Next
CloseStream Stream
------------------------------------------------
8 rabbits equals 1 rabbyte.