delphi UTF-8


本文整理自网络,侵删。

 

 //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

相关阅读 >>

Delphi xe7组件tetheringmanager1发送消息

Delphi android路径 tpath 文件路径,文件管理

Delphi使程序的窗口出现在最前面并激活

Delphi 获取网站验证码的图片

Delphi入门语法

Delphi使焦点固定到一个button上

Delphi二值图像腐蚀算法

Delphi dbgrid 保存txt

Delphi 随机函数单元urandomutils

Delphi�⒆执�传入到windows目前窗口cursor所在位置

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



打赏

取消

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

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

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

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

评论

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