日这样的是什么编码
日本女子盃 如何转换成中文?
[解决办法]
那些是Unicode码,显示成中文要转换成Ansi
以下是网上找的代码,你试试!
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;
[解决办法]
晕,上面的转换有点问题,那是十六进制的unicode转换为Ansi的代码
而日本女子盃 是网页中用十进制表示的unicode
用下面的代码吧:
Function UniCode2Chinese(AiUniCode : Integer) : String;Var ch, cl : String[3]; s : String;Begin s := IntToHex(AiUniCode, 2); cl := '$' + Copy(s, 1, 2); ch := '$' + Copy(s, 3, 2); s := Chr(StrToInt(ch)) + Chr(StrToInt(cl)) + #0; Result := WideCharToString(pWideChar(s));end;