我的 Edit1 里全是数字,我想判断 Edit1 里是否有数字以外的其它字符,并把没用的字符放到 Edit2 里。

解决方案 »

  1.   

    放两个edit,然后这样写
    procedure TForm1.Button1Click(Sender: TObject);
    var
      fsstr,a:string;
      i:integer;
    begin
    a:='';
    if edit1.Text<>'' then
    begin
      fsstr:=trim(edit1.Text);
      for  i:=1  to length(fsstr) do
        begin
        if  ((ord(fsstr[i])<48) or (ord(fsstr[i])>57)) then
        a:=a+fsstr[i];
        end;
        edit2.Text:=a;
    end;
    end;
      

  2.   

    在public下写
    Function str(str):string;//Function Tform1.str(str,string):string; //str是传的是字符
    Var
    newstr:string;
    i:integer;
    begin
      For i:=0 to length(str);
       if not (str[i] in ['0'..'9'] Then
       newstr:=newstr+str[i];  result:=newstr;
    end;在程序里调用
    procedure Tform1.button1click(sender:objects);
    begin
     showmessage(str('652A&C0'));
    edit2.text:=str('652A&C0');
    end;
      

  3.   

    不要让非数字输入到Edit1中,直接输入到Edit2中去
    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if Key >= #20 then
      begin
        if (Key < '0') or (Key > '9') then
        begin
          Edit2.Text := Edit2.Text + Key;
          Key := #0;
        end;
      end
    end;