频道分类

delphi 实现生成手机号段

作者:admin 来源: 日期:2020/4/10 19:58:59 人气: 标签:

 
unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
  txt:tstringlist;
implementation

{$R *.dfm}



  //参数1:要进行补0操作的原始字符串。
//参数2:要将该字符串补0后的位数。   //注:该参数是补0后的字符串长度
function LeftFillZero(str1:string; count:Integer) :string;
var
  temp : string;
  len, idex :Integer;

begin
  len := Length(Trim(str1));
  if (len >= count) then
  begin
    LeftFillZero:= str1;
  end
  else
  begin
    for idex := 0 to count-len-1 do
    begin
     temp := temp + '0';
    end;
    str1 := temp + str1;
    LeftFillZero := str1;
  end

end;

function phonecreate(const sjh: string): string;
var
phonetxt:tstringlist;
i:Integer;
begin//delphitop.com
phonetxt:=tstringlist.create;
    for I := 0 to 9999 do
    begin
      phonetxt.Add(sjh+LeftFillZero(IntToStr(I),4));
    end;
   Result:=phonetxt.text;
   phonetxt.free;
end;


procedure TForm2.FormCreate(Sender: TObject);
begin
memo1.text:=phonecreate('1390347');
end;

end.

第二种方法:
//大悟还俗 DelphiFmx.com(286848376)  提供
-------------------------
procedure TForm1.FormCreate(Sender: TObject);
var
  Idx: Integer;
begin
  Memo1.Lines.BeginUpdate;
  for Idx := 0 to 9999 do Memo1.Lines.Add( '1390347'+Format('%.4d', [Idx]));
  Memo1.Lines.EndUpdate;
end;

上一篇:Delphi中对Excel表格文件的导入和导出操作下一篇:没有资料