大家好,请教一个问题,我用delphi写的接收邮件系统,接收邮件的时候邮件标题显示乱码.
邮件标题出现这样:鏉ㄥ織鍗
正文成这样:琛屾斂蹇樿璋冩暣锛岃ˉ鍙戠粰浣犮€?
请问怎么转换成正常的简体中文?

解决方案 »

  1.   

    UniCode问题以前遇到过,在网上找过一个函数转一下:procedure unicode2gb(const unicodestr:string; var GbStr:String);
    var SourceLength:integer;
      DoneLength:integer;
      AscNo:integer;
      Byte1,Byte2,Byte3:integer;
    begin
     GbStr:='';
     if Trim(unicodestr)='' then exit; SourceLength:=Length(UnicodeStr);
     DoneLength:=1;
     repeat
      AscNo:=ord(UnicodeStr[DoneLength]);
      case (AscNo and $E0) of
      $E0:begin
         Byte1:=(AscNo and $0f) shl 12;
         Inc(DoneLength);
         if DoneLength>SourceLength then break;
         AscNo:=ord(UnicodeStr[DoneLength]);
         Byte2:=(AscNo and $3f) shl 6;
         Inc(DoneLength);
         if DoneLength>SourceLength then break;
         AscNo:=ord(UnicodeStr[DoneLength]);
         Byte3:=AscNo and $3f;
        end;
      $C0:begin
         Byte1:=(AscNo and $1f) shl 6;
         Inc(DoneLength);
         if DoneLength>SourceLength then break;
         AscNo:=ord(UnicodeStr[DoneLength]);
         Byte2:=(AscNo and $3f);
         Byte3:=0;
        end;
      0..$bf:begin
         Byte1:=AscNo;
         Byte2:=0;
         Byte3:=0;
        end;
      end;//case;
       GbStr:=GBStr+widechar(Byte1+Byte2+Byte3);
       Inc(DoneLength);
       if DoneLength>SourceLength then break;
     until DoneLength>=SourceLength;
    end;
      

  2.   

    用delphi2010去试试,字符串默认就是unicode的,也许就不会出现这种问题了
      

  3.   

    多谢liangqingzhi,该函数可以,但是返回的是繁体.并且有些字还是不能完全复原,不过还是谢谢你
      

  4.   

    function UnicodeToUtf8(Dest: PChar; MaxDestBytes: Cardinal; Source: PWideChar; SourceChars: Cardinal): Cardinal; overload;
    function UnicodeToUtf8(Dest: PChar; Source: PWideChar; MaxBytes: Integer): Integer;overload; deprecated;DescriptionCall UnicodeToUtf8 to convert a Unicode string to a null-terminated sequence of UTF-8 characters.Dest receives the resulting null-terminated array of UTF-8 characters.MaxDestBytes or MaxBytes indicates the number of bytes available in the buffer specified by Dest, not counting the byte for the null terminator. Source is an array of Unicode characters.SourceChars is the number of characters in Source. If SourceChars is not specified, Source must be null-terminated.UnicodeToUtf8 returns the number of bytes written to Dest.