在Delphi 2009之前如何处理UTF-8和ANSI转换?

在Delphi 2009之前如何处理UTF-8和ANSI转换?,delphi,unicode,utf-8,delphi-2009,delphi-2006,Delphi,Unicode,Utf 8,Delphi 2009,Delphi 2006,在德尔福2009年,我们有: RichEdit1.Lines.LoadFromFile(OpenDialog1.FileName,TEncoding.UTF8); RichEdit1.Lines.SaveToFile(OpenDialog2.FileName,TEncoding.Unicode); 如果我还没有TEconding,如何在Delphi 2006上实现这一点 有没有办法把那个新的图书馆送回去?还是网络中隐藏着一个解决方案?我相信UTF8Encode和UTF8Decode甚至

在德尔福2009年,我们有:

RichEdit1.Lines.LoadFromFile(OpenDialog1.FileName,TEncoding.UTF8);
RichEdit1.Lines.SaveToFile(OpenDialog2.FileName,TEncoding.Unicode);    
如果我还没有
TEconding
,如何在Delphi 2006上实现这一点


有没有办法把那个新的图书馆送回去?还是网络中隐藏着一个解决方案?

我相信
UTF8Encode
UTF8Decode
甚至在Delphi 2009之前就已经存在了。因此,您可以手动解码/编码字节字符串。(我自己也做过。)

以下是我的Delphi 7项目的一个片段:

function LoadFile(const fn: string): WideString;
var
  f:TFileStream;
  src:AnsiString;
  wx:word;
  i,j:integer;
begin
  if FileExists(fn) then
   begin
    f:=TFileStream.Create(fn,fmOpenRead or fmShareDenyNone);
    try
      f.Read(wx,2);
      if wx=$FEFF then
       begin
        //UTF16
        i:=(f.Size div 2)-1;
        SetLength(Result,i);
        f.Read(Result[1],i*2);
        //detect NULL's
        for j:=1 to i do if Result[j]=#0 then Result[j]:=' ';//?
       end
      else
       begin
        i:=0;
        if wx=$BBEF then f.Read(i,1);
        if (wx=$BBEF) and (i=$BF) then
         begin
          //UTF-8
          i:=f.Size-3;
          SetLength(src,i);
          f.Read(src[1],i);
          //detect NULL's
          for j:=1 to i do if src[j]=#0 then src[j]:=' ';//?
          Result:=UTF8Decode(src);
         end
        else
         begin
          //assume current encoding
          f.Position:=0;
          i:=f.Size;
          SetLength(src,i);
          f.Read(src[1],i);
          //detect NULL's
          for j:=1 to i do if src[j]=#0 then src[j]:=' ';//?
          Result:=src;
         end;
       end;
    finally
      f.Free;
    end;
   end
  else
    Result:='';
end;

我相信
UTF8Encode
UTF8Decode
在Delphi 2009之前就已经存在了。因此,您可以手动解码/编码字节字符串。哇!老兄,你跑得真快!!发布你的答案,因为这是正确的!!!问题已解决。这些函数无法帮助复制
TEncoding.Unicode
,因为这是UTF-16。标准RTF文件只能由7位ASCII字符组成(),为什么要使用UTF8?我制作了一个android应用程序来创建文本文件。但这些都是UTF8。我在delphi中制作了另一个应用程序,可以读取这些txt文件并执行一些操作,但它们必须采用默认的delphi编码(我认为是ANSI),为此,我需要在打开它们时进行解码。