本文整理自网络,侵删。
其中的 utf8 是一种常用的 unicode 编码方式,在目前的网络环境中应用最广,特别是在java,xml这种国际化很强的地方.delphi并不支持原生的utf8字符串,它对 unicode 的支持则是非常好了.将普通字符串赋值给 String 类型即可.而对 uft8 则要用到上面所说的Utf8ToAnsi 等转换函数.好在这些函数都很容易使用,只是大家在使用时要注意自己当前操作的字符串是什么类型就行了.类似的函数还有
AnsiToUtf8
UTF8Decode
Utf8ToAnsi
UTF8Decode
UTF8Encode
下面我是把UTF-8编码的XML 载入MEMO 的代码
procedure TForm1.Button1Click(Sender: TObject);
var s:string;
tt:TMemoryStream;
i:Integer;
Filebuf: array of pchar;
begin
i:=0;
tt:=TMemoryStream.Create;
tt.LoadFromFile('1.xml');
i:=tt.Size ;
SetLength(FileBuf,i);
tt.ReadBuffer(FileBuf[0],i);
s:=StrPas(@Filebuf[0]);
S := Utf8ToAnsi(s) ;
memo1.Lines.Text:= S ;
end;
相关阅读 >>
更多相关阅读请进入《Delphi》频道 >>