思想:通过查找五笔编码文件得到编码的第一个字母 源码如下: unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; ListBox1: TListBox; procedure Edit1Change(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm} function findcode(hz:string;listbox1:Tlistbox):char; var i,j,mid:integer; s:string; ch:char; begin ch:=' '; i:=0; j:=listbox1.count-1; while(i<=j)do begin mid:=(i+j) div 2; s:=listbox1.Items.Strings[mid]; if (hz[1]<s[1]) then j:=mid-1 else if (hz[1]>s[1]) then i:=mid+1 else if (hz[2]<s[2]) then j:=mid-1 else if (hz[2]>s[2]) then i:=mid+1 else begin ch:=s[5]; break; end; end; result:=ch; end;procedure TForm1.Edit1Change(Sender: TObject); var i:integer; str:string; hz:string[2]; ch:char; begin edit2.Text:=''; str:=edit1.text; i:=1; while i<=length(str) do begin if ord(str[i])>160 then begin hz:=copy(str,i,2); ch:=FindCode(hz,listbox1); i:=i+2; end else begin ch:=str[i]; i:=i+1; end; edit2.Text:=edit2.Text+ch; end;end;procedure TForm1.FormCreate(Sender: TObject); begin listbox1.items.LoadFromFile('wb.txt'); end;end.//WB.TXT附后
源码如下:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
ListBox1: TListBox;
procedure Edit1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
function findcode(hz:string;listbox1:Tlistbox):char;
var i,j,mid:integer;
s:string;
ch:char;
begin
ch:=' ';
i:=0;
j:=listbox1.count-1;
while(i<=j)do
begin
mid:=(i+j) div 2;
s:=listbox1.Items.Strings[mid];
if (hz[1]<s[1]) then j:=mid-1
else if (hz[1]>s[1]) then i:=mid+1
else if (hz[2]<s[2]) then j:=mid-1
else if (hz[2]>s[2]) then i:=mid+1
else begin ch:=s[5]; break; end;
end;
result:=ch;
end;procedure TForm1.Edit1Change(Sender: TObject);
var i:integer;
str:string;
hz:string[2];
ch:char;
begin
edit2.Text:='';
str:=edit1.text;
i:=1;
while i<=length(str) do
begin
if ord(str[i])>160 then
begin
hz:=copy(str,i,2);
ch:=FindCode(hz,listbox1);
i:=i+2;
end
else
begin
ch:=str[i];
i:=i+1;
end;
edit2.Text:=edit2.Text+ch;
end;end;procedure TForm1.FormCreate(Sender: TObject);
begin
listbox1.items.LoadFromFile('wb.txt');
end;end.//WB.TXT附后
[email protected]
thanks
注意查收