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替换字符串中的单引号

Delphi 十六进制数转换十进制数

Delphi指针的定义和取值

Delphi Delphi 学习大师qq群讨论的字符串位置替换方法

Delphi释放内存一般这么写

Delphi 读取流 image1 stream 加载到image2 timage 对象

Delphi indy防止假死

Delphi版插apc杀进程驱动源码

Delphi tidhttp抓取页面信息

Delphi在postgresql中读写二进制数据

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



打赏

取消

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

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

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

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

评论

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