作者在 2010-01-25 17:57:16 发布以下内容
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
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,e,c: Integer;
begin
s := Memo1.text;
e := 0;
c := 0;
for i:=1 to Length(s) do
begin
if (Ord(s[i]) >= 33) And (Ord(s[i])<=126) then
begin
Inc(e);
Label1.Caption := '英文字数:'+ IntToStr(e);
end
else
if (Ord(s[i]) >= 127) then
begin
Inc(c);
Label2.Caption := '中文字数:' + IntToStr(c div 2);
end;
end;
end;
end.