; EncodeText Example ; ------------------ ; Requires Extended mode. ; A player name with an accent - one character beyond plain ASCII name$="Café" Print "Encoding the player name: "+name Print "" ; EncodeText returns a new owned Bank of encoded bytes. ; In UTF-8 (the default codec) the é takes two bytes... utf8_bank=EncodeText(name,TEXT_UTF8) If utf8_bank=0 Then RuntimeError TextCodecError() Print "UTF-8: "+BankSize(utf8_bank)+" bytes" ; ...but the legacy Windows-1252 code page stores it in one cp1252_bank=EncodeText(name,TEXT_WINDOWS_1252) If cp1252_bank=0 Then RuntimeError TextCodecError() Print "Windows-1252: "+BankSize(cp1252_bank)+" bytes" Print "" ; Show the actual bytes of each encoding Print "UTF-8 bytes: "+BankHex(utf8_bank)+" (c3 a9 = é)" Print "Windows-1252 bytes: "+BankHex(cp1252_bank)+" (e9 = é)" ; The returned Banks are owned by us and must be freed FreeBank cp1252_bank FreeBank utf8_bank Print "" Print "Press any key to close the example" WaitKey End ; Render a Bank's bytes as lowercase hex Function BankHex$(bank) hex_text$="" For i=0 To BankSize(bank)-1 hex_text=hex_text+Right(Hex(PeekByte(bank,i)),2) Next Return Lower(hex_text) End Function