delphi代码
- procedure TForm1.btn1Click(Sender: TObject);
- var i,e,c:integer;
- s:string;
- begin
- s:=mmo1.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;