根据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;

Last modification:January 7th, 2011 at 10:03 pm
如果觉得我的文章对你有用,请随意赞赏