delphi UTF-8  
官方Delphi 学习QQ群: 682628230(三千人)\n
频道

delphi UTF-8


 //Utf8存、取
procedure TForm1.Button1Click(Sender: TObject);
var
  S: string;
begin
//存
  with TMemoryStream.Create do try
    S := #$EF#$BB#$BF;
    
Write(S[1], Length(S));
    S := AnsiToUtf8(Memo1.Text);
    
Write(S[1], Length(S));
    Position :=
0;
    SaveToFile(
'c:\temp\temp.txt');
  
finally
    Free;
  
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  S: string;
begin
  //取
  if not FileExists('c:\temp\temp.txt') then Exit;
  
with TMemoryStream.Create do try
    LoadFromFile('c:\temp\temp.txt');
    SetLength(S, Size);
    
Read(S[1], Length(S));
    
if Copy(S, 1, 3) <> #$EF#$BB#$BF then Exit;
    Memo2.Text := Utf8ToAnsi(Copy(S,
4, MaxInt));
  
finally
    Free;
  
end;
end;

http://hi.baidu.com/sail2000/blog/item/0a8cd52a6537a52dd42af180.html


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.46568322181702 seconds