本文整理自网络,侵删。
根据asc码分别进行统计,看有多少字母和符号,汉字分开统计,一个汉字算计数1
function TFrm_main.MsgCounter(str: string): string;
var
s:string; //保存字符串
i,e,c:integer;//保存变量
begin
s:=str;
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);
end
else
if (ord(s[i])>=127) then
//判断字符的顺序号
begin
inc(c);
end;
end;
Result:=IntToStr(e+(c div 2));
end;
文章来源于: http://www.samool.com/archives/41374/
相关阅读 >>
Delphi net.httpclient正则批量获取网页代码中的数值
Delphi pagecontrol.ttabsheet与drivecombobox.items同步
Delphi firedac 下的 sqlite [8] - 自定义函数
更多相关阅读请进入《Delphi》频道 >>