Delphi 字符串保存UTF-8过程


本文整理自网络,侵删。

 
procedure SaveAsUTF8( const Name:String; Data: TStrings );
const
  cUTF8: array [1..3] of byte = ($EF,$BB,$BF);
var
  W_TXT: UTF8String;
  fs: TFileStream;
  Trimmed: AnsiString;
begin
  Trimmed := TRIM(Data.Text);
  if Trimmed <> '' then begin
    W_TXT:= AnsiToUTF8(Trimmed);
    fs:= TFileStream.Create( Name, fmCreate );
    try
      fs.WriteBuffer( cUTF8[1], sizeof(cUTF8) );
      fs.WriteBuffer( W_TXT[1], Length(W_TXT)*Sizeof( W_TXT[1] ));
    finally
      fs.free
    end;
  end;
end;

相关阅读 >>

学习使用Delphi for android 调用java类库

Delphi保存网页中的图片

Delphi 运行js

Delphi 字符串加密解密代码

Delphi 创建应用程序的快捷方式

Delphi char string

Delphi webbrowser ie 窗口选择中,选中的文字内容

Delphi读写utf-8、unicode格式文本文件

Delphi combobox1dropdown 生成动态下拉列表

Delphi 安卓图像压缩bitmapcompress

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...