Delphi Code Conversion

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.