把中文转换成Unicode字符
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure Edit1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Edit1Change(Sender: TObject);
var s: string;
i, j, k: integer;
a: array[1..1000] of char;
begin
s:='';
for i:=1 to Length(Edit1.Text) do begin
j:=Integer(Edit1.Text);
s:=s+Copy(Format('%X ',[j+$100]) ,2,3);
end;
Edit2.Text:=s;
StringToWideChar(Edit1.Text, @(a[1]), 500);
s:=''; i:=1;
while ((a<>#0) or (a[i+1]<>#0)) do begin
j:=Integer(a); k:=Integer(a[i+1]);
s:=s+Copy(Format('%X ',[j*$100+k+$10000]) ,2,5);
i:=i+2;
end;
Edit3.Text:=s;
end;
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;