如何转换。java中两个函数就搞定了。Delphi中如何实现

解决方案 »

  1.   

    Utf8encode和utf8decode,在system单元内
      

  2.   

    //  system.pas 中的内容。。// UnicodeToUTF8(3):
    // UTF8ToUnicode(3):
    // Scans the source data to find the null terminator, up to MaxBytes
    // Dest must have MaxBytes available in Dest.
    // MaxDestBytes includes the null terminator (last char in the buffer will be set to null)
    // Function result includes the null terminator.function UnicodeToUtf8(Dest: PChar; Source: PWideChar; MaxBytes: Integer): Integer; overload; deprecated;
    function Utf8ToUnicode(Dest: PWideChar; Source: PChar; MaxChars: Integer): Integer; overload; deprecated;// UnicodeToUtf8(4):
    // UTF8ToUnicode(4):
    // MaxDestBytes includes the null terminator (last char in the buffer will be set to null)
    // Function result includes the null terminator.
    // Nulls in the source data are not considered terminators - SourceChars must be accuratefunction UnicodeToUtf8(Dest: PChar; MaxDestBytes: Cardinal; Source: PWideChar; SourceChars: Cardinal): Cardinal; overload;
    function Utf8ToUnicode(Dest: PWideChar; MaxDestChars: Cardinal; Source: PChar; SourceBytes: Cardinal): Cardinal; overload;{ WideString <-> UTF8 conversion }function UTF8Encode(const WS: WideString): UTF8String;
    function UTF8Decode(const S: UTF8String): WideString;{ Ansi <-> UTF8 conversion }function AnsiToUtf8(const S: string): UTF8String;
    function Utf8ToAnsi(const S: UTF8String): string;