⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 本光盘是《Delphi 7应用教程》一书的配套光盘
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Label3: TLabel;
    Edit3: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
Function iszimu(s:String):Boolean;//自定义判断字母的函数
begin
  if (s<='z')And(s>='a') Or (s<='Z')And(s>='A') then
  //注意上面逻辑表达式的运算顺序
    iszimu:=True
  else
    iszimu:=False;
end;
Function isshuzi(s:String):Boolean;//自定义判断数字字符的函数
begin
  if (s>='0')And(s<='9') then
    isshuzi:=True
  else
    isshuzi:=False;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  t:String;
  m,n:Integer;
  b1,b2:Boolean;
begin
  Edit2.Text:='';
  Edit3.Text:='';
  m:=Length(Edit1.Text);//将字符串的长度赋给m
  for n:=1 to m do
    begin
      t:=Copy(Edit1.Text,n,1);//每次截取一个字符
      b1:=isshuzi(t);  //将数字函数的返回值赋值给b1
      b2:=iszimu(t);   //将字母函数的返回值赋值给b2
      if b1 then
        Edit2.Text:=Edit2.Text+t;//如果是数字就添加到数字编辑框
      if b2 then
        Edit3.Text:=Edit3.Text+t;//如果是字母就添加到字母编辑框
    end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -