随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

//添加 Memo1、Label1、Label2、还有Button1
procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
  i,sum,e,c,t: Integer;
begin
  s := Memo1.Text;
  e := 0;
  c := 0;
  sum := Length(s);

  for i := 0 to sum do
  begin
    if (Ord(s[i]) >= 33) and (Ord(s[i]) <= 126) then
    begin
      Inc(e);
      Label1.Caption := '字母数: ' + IntToStr(e);
    end;

    if Ord(s[i]) >= 127 then
    begin
      Inc(c);
      Label2.Caption := '汉字数: ' + IntToStr(c div 2);
    end;
  end;
end;
posted on 2007-12-08 18:52  万一  阅读(...)  评论(...编辑  收藏