delphi 多种编码转换


本文整理自网络,侵删。

 function AnsiToUnicode(Ansi: string):string; 
var
s:string;
i:integer;
j,k:string[2];
a:array [1..1000] of char;
begin
s:='';
StringToWideChar(Ansi,@(a[1]),500);
i:=1;
while ((a[i]<>#0) or (a[i+1]<>#0)) do begin
j:=IntToHex(Integer(a[i]),2);
k:=IntToHex(Integer(a[i+1]),2);
s:=s+k+j;
i:=i+2;
end;
Result:=s;
end;

function ReadHex(AString:string):integer;
begin
Result:=StrToInt('$'+AString)
end;

function UnicodeToAnsi(Unicode: string):string;
var
s:string;
i:integer;
j,k:string[2];
begin
i:=1;
s:='';
while i<Length(Unicode)+1 do begin
j:=Copy(Unicode,i+2,2);
k:=Copy(Unicode,i,2);
i:=i+4;
s:=s+Char(ReadHex(j))+Char(ReadHex(k));
end;
if s<>'' then
s:=WideCharToString(PWideChar(s+#0#0#0#0))
else
s:='';
Result:=s;
end;

function ToGBK(Str:string):string;
begin
result := inttohex(byte(Str[1])*$100+byte(Str[2]),2);
end;

相关阅读 >>

Delphi xe2 新增 system.zip 单元, 可用一句话压缩整个文件夹了

Delphi 获取网卡信息

[译]rad studio 10.4 新变化:面向控件的 vcl 样式管理

Delphi webbrowser1 缩放网页

Delphi 手机号码库段号地区查询

Delphi 获取unixtime

Delphi实现网卡状态检测

Delphi 提取时间成分

Delphi 比较两个位图是否相同

Delphi调用sql分页存储过程实例

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



打赏

取消

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

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

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

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

评论

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