1, Delphi Utf-8 conversion-findumars-blog Park. html
Https://www.cnblogs.com/findumars/archive/2013/12/26/3492891.html
The new version of Delphi should not be so troublesome, as long as directly in the Ansistring, widestring, utf8string between the assign will be self-help you do the conversion (not used, do not know if it is true).
But ... Still using Delphi 3/5, so ... Had to turn himself:
UnitUtil_utf8;Interface usesWindows;typeutf8string=ansistring; functionAnsitowide (Consts:ansistring): widestring; functionWideToUTF8 (Constws:widestring): utf8string; functionAnsiToUTF8 (Consts:ansistring): utf8string; functionUtf8towide (Constus:utf8string): widestring; functionWidetoansi (Constws:widestring): ansistring; functionUtf8toansi (Consts:utf8string): ansistring; Implementation functionAnsitowide (Consts:ansistring): widestring;varLen:integer; ws:widestring;beginResult:="';if(Length (S) =0) ThenExit;len:=multibytetowidechar (CP_ACP,0, PChar (s),-1,Nil,0); SetLength (WS, Len); MultiByteToWideChar (CP_ACP,0, PChar (s),-1, Pwidechar (WS), Len); Result:=ws;End; functionWideToUTF8 (Constws:widestring): utf8string;varLen:integer; us:utf8string;beginResult:="';if(Length (WS) =0) ThenExit;len:=widechartomultibyte (Cp_utf8,0, Pwidechar (WS),-1,Nil,0,Nil,Nil); SetLength (US, Len); WideCharToMultiByte (Cp_utf8,0, Pwidechar (WS),-1, PChar (US), Len,Nil,Nil); Result:=us;End; functionAnsiToUTF8 (Consts:ansistring): utf8string;beginResult:=WideToUTF8 (Ansitowide (S));End; functionUtf8towide (Constus:utf8string): widestring;varLen:integer; ws:widestring;beginResult:="';if(Length (US) =0) ThenExit;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;End; functionWidetoansi (Constws:widestring): ansistring;varLen:integer; s:ansistring;beginResult:="';if(Length (WS) =0) ThenExit;len:=widechartomultibyte (CP_ACP,0, Pwidechar (WS),-1,Nil,0,Nil,Nil); SetLength (S, Len); WideCharToMultiByte (CP_ACP,0, Pwidechar (WS),-1, PChar (s), Len,Nil,Nil); Result:=s;End; functionUtf8toansi (Consts:utf8string): ansistring;beginResult:=Widetoansi (Utf8towide (S));End; End.
is to use the Win32 API directly.
PS. Old VCL only supports Ansi, so ... Widestring and utf8string (the same definition as ansistring) do not have the right to display in the VCL.
Original: http://blog.teatime.com.tw/1/post/419
2.
3.
Delphi Code Conversion