Languages & Coding > BlitzMax / BlitzMax NG

Convert WriteStream into UTF8?

(1/1)

Yellownakji:


--- Code: ---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)

--- End code ---

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?

TomToad:
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: ---SuperStrict
Local Stream:TStream = WriteStream("utf8::MyFile.txt")
For Local i:Int = 0 To 65535
WriteLine(Stream,Chr(i))
Next
CloseStream Stream

--- End code ---

Navigation

[0] Message Index

Go to full version