- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi 如何将Memo或RichEdit保存为UTF 8文本文件?
const
UTF8BOM: array[0..2] of Byte = ($EF, $BB, $BF);
var
UTF8Str: UTF8String;
FS: TFileStream;
begin
UTF8Str := UTF8Encode(Memo1.Text);
FS := TFileStream.Create('C:\path to\file.txt', fmCreate);
try
FS.WriteBuffer(UTF8BOM[0], SizeOf(UTF8BOM));
FS.WriteBuffer(PAnsiChar(UTF8Str)^, Length(UTF8Str));
finally
FS.Free;
end;
end;