註解:
ANSI 'American Standard Code for Information Interchange' 美國信息互換標準代碼 ANSI的'Ascii'編碼
Unicode 'Universal Multiple-Octet Coded Character Set' 簡稱 UCS, 俗稱 'Unicode'
UTF 'UCS Transfer Format'
DBCS 'Double Byte Charecter Set' 雙字節字符集html
相關重要函數過程:
WinAPI:
MultiByteToWideChar WideCharToMultiByte
相關參數(CodePage)ide
CP_ACP ANSI code page
CP_MACCP Not supported
CP_OEMCP OEM code page
CP_SYMBOL Not supported
CP_THREAD_ACP Not supported
CP_UTF7 UTF-7 code page
CP_UTF8 UTF-8 code page函數
單元System.pas:
function StringToWideChar(const Source: string; Dest: PWideChar; DestSize: Integer): PWideChar;
function WideCharToString(Source: PWideChar): string;
function WideCharLenToString(Source: PWideChar; SourceLen: Integer): string;
procedure WideCharToStrVar(Source: PWideChar; var Dest: string);
procedure WideCharLenToStrVar(Source: PWideChar; SourceLen: Integer; var Dest: string);編碼
type
UCS2Char = WideChar; PUCS2Char = PWideChar;
UCS4Char = type LongWord;
UCS4String = array of UCS4Char;
function PUCS4Chars(const S: UCS4String): PUCS4Char;
function WideStringToUCS4String(const S: WideString): UCS4String;
function UCS4StringToWideString(const S: UCS4String): WideString;spa
function UnicodeToUtf8(Dest: PChar; Source: PWideChar; MaxBytes: Integer): Integer; overload; deprecated;
function Utf8ToUnicode(Dest: PWideChar; Source: PChar; MaxChars: Integer): Integer; overload; deprecated;code
function UnicodeToUtf8(Dest: PChar; MaxDestBytes: Cardinal; Source: PWideChar; SourceChars: Cardinal): Cardinal; overload;
function Utf8ToUnicode(Dest: PWideChar; MaxDestChars: Cardinal; Source: PChar; SourceBytes: Cardinal): Cardinal; overload;
function UTF8Encode(const WS: WideString): UTF8String;
function UTF8Decode(const S: UTF8String): WideString;orm
function AnsiToUtf8(const S: string): UTF8String;
function Utf8ToAnsi(const S: UTF8String): string;htm
原文出處:https://www.cnblogs.com/kmhr/p/8443967.htmlblog