1 回答

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊
對(duì)于這個(gè)問(wèn)題,我在我的軟件中采用求ASC碼值的方法,將每一位的ASC碼值加起來(lái),再case of,(因?yàn)槲覀兪孪戎谰唧w的字符串,要不然,您怎么比較呢?)
我做的例子的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);{假設(shè)為a 97}
98:messagebox(0,'51','51',mb_ok);{假設(shè)為b 97}
{常數(shù)N:語(yǔ)句N(xiāo)
...
}
else caption:=inttostr(i);
end;
end;
end.
-----------------------------------------------
unit1窗體中,就一個(gè)組件,ord()函數(shù)是求字符的原始值 ord(s[k]),就是ASC碼
- 1 回答
- 0 關(guān)注
- 125 瀏覽
添加回答
舉報(bào)