本文整理自网络,侵删。
//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
相关阅读 >>
在rad studio Delphi或c++安卓应用中使用自定义java库
Delphi xe datasnap服务器获取客户端ip地址
更多相关阅读请进入《Delphi》频道 >>