Unicode Chr()

Just starting out? Need help? Post your questions and find answers here.
bumblebee
New User
New User
Posts: 5
Joined: Tue Feb 22, 2005 8:09 pm
Location: England
Contact:

Unicode Chr()

Post by bumblebee »

Don't know if this has been mentioned before or not - I did have a quick look.
But anyway, I've suddenly (after all these years!) decided I need Unicode in my life!

In the process of creating a little code, I came across this problem, and work-around.
So I extracted it to the smallest amount of code I could, to demonstrate.

Please note for anyone who may find this post via a search engine, that you must enable the "Create Unicode Executable" in your compiler options in order for this code to work.

Code: Select all

; Note to self: Make sure you set the "Create Unicode Executable" option in the compiler options!
; setup
OpenWindow(1,10,10,400,200,"test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ListViewGadget(1,1,1,WindowWidth(1),WindowHeight(1))



; attempt 1.
AddGadgetItem(1,-1, Chr(1069)) ; display the ascii char "-"  not the unicode one. 

; attempt 2
txt.s=""
num.l=1069
txt = txt + Chr(num)
AddGadgetItem(1,-1, txt) ; this displays the unicode.



; wait for close window.
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
It seems to me that the Chr() code does not switch to the Wide Char version, or perhaps the literal value 1069 is truncated to a byte. Either way, we perhaps need a UChr() command, or for the current one to behave nicely with literals.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Unicode Chr()

Post by Trond »

Chr(literal number) is optimized into a string on compile time. If your source file encoding is set to plain text, unicode characters will be truncated to ascii. Set your source file encoding to UTF-8 to prevent this problem.
Post Reply