如何判断edit 中汉字的个数能给段代码最好谢谢!!

解决方案 »

  1.   

    var s:string;
    i,e,c:integer;
    begin
      s:=Edit1.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;
      

  2.   

    那就在EDIT控件的ONChange()是上面的代码.
      

  3.   

    把1楼的代码放到一个函数里..然后在Edit的OnChange事件里调用函数就可以了.
      

  4.   

    哦,我发现你不会用函数,呵呵,那就告诉你一个更简单的方法吧

    interfaceuses
      加入StrUtils单元procedure TForm1.Edit1Change(Sender: TObject);
    var
      i,Count: Integer;
    begin
      for i := 1 to Length(Edit1.Text) do
      begin
        if ByteType(Edit1.Text,i) <> mbSingleByte then
        Count := Count + 1;
      end;
      showMessage('中文字有: '+IntToStr(Count div 2)+' 个');
    end;Email:[email protected]
      

  5.   

    var s:String;
        ws:WideString;
    begin
      ws:=s;
      Len:=Length(ws);
    end;
      

  6.   

    同意这个观点: hewei2003()