PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → UNICODE Hell :(
UNICODE Hell :(
Débuté par Patrick Thijs, 11 avr. 2018 17:14 - 5 réponses
Posté le 11 avril 2018 - 17:14
Hello Everyone,

I'm having big troubles with Unicode strings. I don't think that it's a WinDev problem but more a lack of knowledge by myself.

Here's what I'm trying to do :

I'm communicating with an API on a webserver. The communication itself seems to be working, the problem is that I'm receiving unicode characters and don't know how to handle them correctly.

This the connecting part of the code

MyRequest.URL = gsWS_URL + "get_user/" + NumToString(gnClientNumber)
MyRequest.ContentType = "application/json"
MyRequest.Header["X-API-KEY"] = gsTokenCode
MyRequest.Header["Username"] = gsWS_User
MyRequest.Header["Password"] = gsWS_Passw

gMyResponse = HTTPSend(MyRequest)

sResponse = gMyResponse..Content

sResponse is decladered as a normal string, and contains something like this :

"result":"success","DealerID":"17","Koppelveld":"5069","RoepNaam":"TESTDONGLE Patrick Thijs 1","PC_KEY":"PATRICK8","DatabaseTaal":"1","ProgrammaTaal":"1","UserLevel":"5","U_Adres":"Rik Woutersstraat 27","U_Postcode":"2800","U_Gemeente":"Mechelen \?\?\?","U_Land":"BE"

The problem is in the part "U_Gemeente":"Mechelen \?\266a\?"
I can't get this string to be displayed correctly, the unicode codes should display 3 musicnotes right after the word Mechelen.
But i'm not able to achieve this.

Is there anyone who can put me on the right track with this ?
Your help is really appreciated

grtz

Patrick
Posté le 11 avril 2018 - 19:35
Hi Patrick,

your fist problem is here :
>>sResponse is decladered as a normal string<<

There is no such thing as a 'NORMAL' string...

A string is either ansi or unicode, and both are 'normals' (or neither is).

Now if you don't SPECIFY ansi or unicode, the string is still ansi OR unicode, based on your current configuration, which means that it is a VERY BAD idea not to specify...

Again, nothing NORMAL in any of this.

Your second problem is that \? is NOT REALLY a unicode string... it's a non unicode representation of a unicode character...

A unicode string is simply a 2 bytes per char representation of characters (ie hexa code 266A is the value of your char)

Now, the following is supposition:
as the transport system of your webservice is working in ansi, your special unicode character, when there are some, are encoded the \? way.

If you want to get your unicode string, you can probably do by extracting the hexa value (266a from \?) and using it with charactunicode

Best regards
Posté le 11 avril 2018 - 20:00
Hello Fabrice,

You're right, there's no such thing as a "normal" string, I've tried ANSI as well as UNICODE, without any result.
But the information you wrote should help me to to solve the problem.
I'll let you know if I get it working

grtz

Patrick
Posté le 11 avril 2018 - 20:04
Hi

Pls see below clumsy code:


sHex1, sHex2, sHex3 is Ansi string
sUnicode is Unicode String

sAnsi is string = [
"U_Gemeente":"Mechelen \?\266a\?"
]



sHex1=extractString(sAnsi, 2, "\")
sHex1=replace(sHex1,"u","")

sHex2=extractString(sAnsi, 3, "\")
sHex2=replace(sHex1,"u","")

sHex3=extractString(sAnsi, 4, "\")
sHex3=replace(sHex3,"u","")
sHex3=replace(sHex3, """","")



sUnicode = CaractUnicode(hexaToInt(sHex1)) + CaractUnicode(hexaToInt(sHex3))+ ...
CaractUnicode(hexaToInt(sHex3))

trace(sUnicode)
// you should see musical note

HTH
King
Posté le 11 avril 2018 - 20:32
Hello King,

that's already a good starting point.
Thank you very much !

grtz

Patrick
Posté le 12 avril 2018 - 05:25
unicode in WD windows is UTF-32 LE which is default use in windows but it's not same with UTF-16 which default use in non-windows (linux, android,...).