look at code
dim as wstring * 10 ws = "你好"
printf("%x \n", ws[0]) 'print 4f60
printf("%x \n", ws[1]) 'print 597d
printf(!"%ws\n", ws) 'print 你好
Dim As Zstring Ptr zsp
zsp = Strptr(ws)
For i As Integer = 0 To 3
printf(!"%x ", (*zsp)) 'here , print 60 4f 7d 59, It's different from the print above.
Next
'I output it to file
Dim As FILE Ptr f
f=fopen("debug.txt", "wb")
If f<> 0 Then
fputs(Strptr(ws), f)
End If
fclose(f)
'then file raw data also is 60 4f 7d 59 , It's bad order, "你好"characters can't be show correctly, the right order is 4f 60 59 7d
It's a bug? how do I get the order right?
[Solved]Why wstring data is different from its raw data
[Solved]Why wstring data is different from its raw data
Last edited by guawoo on Mar 16, 2019 9:40, edited 2 times in total.
Re: Why wstring data is different from its raw data
It depends on what is "right" for you. Under the hood, memory is
60 4F 7D 59 你好
You are under Windows or Linux?
The issue here is endianness:
printf("0: %x \n", ws[0]) ' print 4f60 this is a WORD
printf("%x ", (*zsp)) ' this prints BYTEs
60 4F 7D 59 你好
You are under Windows or Linux?
The issue here is endianness:
printf("0: %x \n", ws[0]) ' print 4f60 this is a WORD
printf("%x ", (*zsp)) ' this prints BYTEs
Re: Why wstring data is different from its raw data
oh, thank you @jj2007, your answer inspired me! I get the problem with my code, the source file encoding was wrong, now I changed it to utf-8.bom from utf-8, that everything work ok:)
(btw: I use windows)
Thank you so much.
(btw: I use windows)
Thank you so much.
Re: [Solved]Why wstring data is different from its raw data
Glad I could help, and welcome to the forum!