delphi 统计中英文字个数的例子


本文整理自网络,侵删。

 想在文本控件TMemo中,分别对中、英文的字符数进行统计,我们可以通过把字符转换为数值来进行判断,Ord()函数把字符转换为对应的数值,值33-126为键盘可使用字符,值127以上的为未知字符,即为汉字.
代码如下:
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;

相关阅读 >>

Delphi 新建文件夹函数

Delphi Delphi tparallel cleanup needed用法

Delphi中关闭“返回值…可能未定义”的警告

Delphi7调用Delphi xe2 中间层注意事项

Delphi 获取unigui 控件id 及获取html值

Delphi apihook

Delphi xe5 android程序常用的unit

Delphi for 循环 to和downto的理解

Delphi 动态调用chm文件

incsecond:将一个tdatetime变量加减一定数量的秒数

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...