如果你是在文本框输入一串字符. procedure TForm1.Button1Click(Sender: TObject); var str: string; msg:string; i,a,b,c,d: integer; begin a:=0;b:=0;c:=0;d:=0; str:=edit1.Text; for i:=1 to length(edit1.Text) do begin if str[i]=' ' then inc(a) else if str[i] in ['0'..'9'] then inc(b) else if ('A'<str[i]) and (str[i]<'z')then inc(c) else inc(d);