不包括标点符号。用ASCII码数值来进行判断结果不对啊

解决方案 »

  1.   

    最简单的办法是:
    length(yourstring)-length(widestring(yourstring))=汉字个数
    2*length(widestring(yourstring))-length(yourstring)=英语个数
    ////////////////////////////////////////
    中国使用的是汉字,而又夹杂这些英文,这样我们在数字数时就麻烦了,电脑是按字节来计算,一个汉字算两个字,而中国人的习惯是一个汉字就是一个字,所以通过电脑来计算必须解决下列问题:
    利用文本控件Tmemo来存放文章,分别对中、英文的字符数进行统计,我们可以通过把字符转换为ASCII码数值来进行判断,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;