• Delphi7中Unicode,ANSI,UTF编码问题


    注解:
      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;

  • 相关阅读:
    实例下载
    js跳转
    navicat怎么导出和导入数据表
    navicate怎么用sql语句插入一条语句
    svn提交时出现很多乱文件怎么解决
    随机显示星星(点击可删除)
    html节点属性操作
    利用节点更改table内容
    TreeView添加treeView1_NodeMouseClick----多么痛的领悟。。。
    IP addresses in C#
  • 原文地址:https://www.cnblogs.com/kmhr/p/8443967.html
Copyright © 2020-2023  润新知