1 回答
TA贡献1853条经验 获得超9个赞
对于这个问题,我在我的软件中采用求ASC码值的方法,将每一位的ASC码值加起来,再case of,(因为我们事先知道具体的字符串,要不然,您怎么比较呢?)
我做的例子的unit1窗体如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
i,j,k:integer;
begin
s := Edit1.Text;
j := length(s);
i :=0;
for k :=1 to j do
i := i ord(s[k]);
case i of
97:messagebox(0,'50','50',mb_ok);{假设为a 97}
98:messagebox(0,'51','51',mb_ok);{假设为b 97}
{常数N:语句N
...
}
else caption:=inttostr(i);
end;
end;
end.
-----------------------------------------------
unit1窗体中,就一个组件,ord()函数是求字符的原始值 ord(s[k]),就是ASC码
- 1 回答
- 0 关注
- 100 浏览
添加回答
举报