首页 > Windows开发 > 详细

Delphi7中Unicode,ANSI,UTF编码问题

时间:2019-07-09 13:12:03      阅读:153      评论:0      收藏:0      [点我收藏+]

注解:
  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‘ 双字节字符集

相关重要函数过程:
WinAPI:
  MultiByteToWideChar WideCharToMultiByte
  相关参数(CodePage)

    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;

function UnicodeToUtf8(Dest: PChar; Source: PWideChar; MaxBytes: Integer): Integer; overload; deprecated;
function Utf8ToUnicode(Dest: PWideChar; Source: PChar; MaxChars: Integer): Integer; overload; deprecated;

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;

function AnsiToUtf8(const S: string): UTF8String;
function Utf8ToAnsi(const S: UTF8String): string;

Delphi7中Unicode,ANSI,UTF编码问题

原文:https://www.cnblogs.com/kmhr/p/8443967.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!