Delphi中判断字母与汉字
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;
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;
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇: sql语句分别按日,按周,按月,按季统计金额
