Delphi: 将unicode码转换为汉字

Delphi: 将unicode码转换为汉字
Night @ 2004-12-01 21:12

function UnicodeToAnsi(SubUnicode: string):string;  //将unicode码转换为汉字
   var a:array[0..500] of char;
      s1,s2:char;
      substr1,substr2,s:string;
      str:string;
      i:integer;
   begin
     if length(SubUnicode) mod 4 = 0 then
     Begin



       str:='';
       for i:=1 to length(SubUnicode) div 4 do
       Begin
         s:='';
         substr1:=copy(SubUnicode,i*4-3,2);
         substr2:=copy(SubUnicode,i*4-1,2);
         s1:=chr(hextoint(substr1));
         s2:=chr(hextoint(substr2));
         s:=s+s2+s1;
         strpcopy(a,s);
         str:=str+copy(widechartostring(@(a[0])),1,2);
       end;
       result:=str;
     end;
   end;



function HexToInt(hex:string):cardinal;
const cHex='0123456789ABCDEF';
var mult,i,loop:integer;
begin
      result:=0;
      mult:=1;
      for loop:=length(hex)downto 1 do
      begin
       i:=pos(hex[loop],cHex)-1;
       if (i<0) then i:=0;
       inc(result,(i*mult));
       mult:=mult*16;
      end;
end;

posted on 2005-02-22 14:12  Kouwell  阅读(5838)  评论(7编辑  收藏  举报

导航