Home > Back-end >  Delphi xe10 utf8 decoding problems
Delphi xe10 utf8 decoding problems

Time:09-17


Delphi xe10 utf8 decoding problems
I send a
32227128144,49,55,53,227,128,145,230,185,150

I convert sByte: Tbytes;

I use utf8toAnsi (ansistring (sByte))
There will be the phenomenon of gibberish, excuse me, what to solve

xe10

CodePudding user response:

Test a lot of function
The function CharToWide (const S: a String; CodePage: Word) : WideString;
The function WideToChar (const WS: WideString; CodePage: Word) : String;
The function CharToChar (const S: a String; CP1, contact international.like apply SSDS: Word) : String;
The function AnsiToWide (const S: AnsiString) : WideString;
The function WideToUTF8 (const WS: WideString) : UTF8String;
The function AnsiToUTF8 (const S: AnsiString) : UTF8String;
The function UTF8ToWide (const US: UTF8String) : WideString;
The function WideToAnsi (const WS: WideString) : AnsiString.
The function UTF8ToAnsi (const S: UTF8String) : AnsiString.
The function StringToWideStringEx (const S: a string; CodePage: Word) : WideString;
The function WideStringToStringEx (const WS: WideString; CodePage: Word) : string;
Finally found is this:
 
The function UTF8ToWide (const US: UTF8String) : WideString;
Var
Len: integer;
Ws: WideString;
The begin
Result:=';
If (Length (US)=0) then
exit;
Len:=MultiByteToWideChar (CP_UTF8, 0, PChar (US), 1, nil, 0).
SetLength (ws, len);
MultiByteToWideChar (CP_UTF8, 0, PChar (US), 1, PWideChar (ws), len);
Result:=ws;
The end;

You given string, converted to an ansistring string, and then use this function, the result is:
[175] lake


  • Related