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 vclunzip组件解压缩文件用法

Delphi 请求时间,为当前时间,数值为1970-01-01以来的毫秒数

shellexecute()和winexec()区别

Delphi tstringlist自定义排序

Delphi xe5 将Delphi code从winos 迁移到ios与android

delph做的百叶窗小程序

Delphi xe6 android 界面皮肤美化 用stylebook

Delphi 本地数据库备份与还原(Delphi)

Delphi的tstreamreader逐行读取文本文件

Delphi中exit,abort,break,continue,halt,runerro 的区别

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



打赏

取消

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

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

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

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

评论

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