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 在memorystream查找字符串

Delphi xe5调用外部扫描程序――谷歌 zxing

firemonkey下使用stylebook的一些经验

Delphi android 安卓中保持屏幕常亮

在rad studio Delphi或c++安卓应用中使用自定义java库

Delphi判断程序是否无响应

如何访问局域网的access数据库

解放程序员!Delphi带来app开发革命

wmi技术介绍和应用

Delphi xe datasnap服务器获取客户端ip地址

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



打赏

取消

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

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

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

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

评论

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