Delphi 读取UTF-8格式的文件内容


本文整理自网络,侵删。

 
读取UTF-8格式的文件内容

function LoadUTF8File(AFileName: string): string;
var  ffileStream:TFileStream; 
         fAnsiBytes: string;
         S: string;
begin
            ffileStream:=TFileStream.Create(AFileName,fmOpenRead);
            SetLength(S,ffileStream.Size); 
            ffileStream.Read(S[1],Length(S));
            fAnsiBytes:= UTF8Decode(Copy(S,4,MaxInt));
           Result:= fAnsiBytes;
end;

写入UTF-8编码格式的文件
procedure SaveUTF8File(AContent:string;AFileName: string);
var ffileStream:TFileStream;
        futf8Bytes: string;
       S: string;
begin
       ffileStream:=TFileStream.Create(AFileName,fmCreate); 
       futf8Bytes:= UTF8Encode(AContent); 
       S:=#$EF#$BB#$BF; 
       ffileStream.Write(S[1],Length(S)); 
       ffileStream.Write(futf8Bytes[1],Length(futf8Bytes)); 
       ffileStream.Free;
end;

相关阅读 >>

Delphi 关于字符串的一些使用技巧

processid, process handle, window handle 之间的互相转换

Delphi中轻松实现tidftp的断点续传

Delphi读取文本文件的最后一行

Delphi 把exe嵌入到自己的exe中。Delphi xe3

Delphi 遍历某字段并插入到combobox

Delphi显示圆形头像circle image

Delphi+汇编例子

Delphi xe android 调试错误:connection closed gracefully

Delphi android 按包名判断是否安装了app

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



打赏

取消

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

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

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

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

评论

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

    正在狠努力加载,请稍候...