当前位置:编程学习 > Delphi >>

如何得到汉字的unicode (delphi)

如上:
如何得到汉字的unicode
答案:
你需要的是这样的函数吧? 


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<>#0) or (a[i+1]<>#0)) do begin

j:=IntToHex(Integer(a),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;

上一个:请问这段Delphi代码是什么意思?
下一个:delphi做的程序怎样实现密码找回功能。

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,