zoukankan      html  css  js  c++  java
  • delphi 截取指定符号之间的字符串-随机读取

    unit Unit1;

    interface

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

    type
      TForm1 = class(TForm)
        test: TMemo;
        Button1: TButton;
        Memo1: TMemo;
        Label1: TLabel;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}

    function   PosEx(const   Source,   Sub:   string;   Index:   integer):   integer;
    var
       Buf                               :   string;
       i,   Len,   C                   :   integer;
    begin
       C   :=   0;
       Result   :=   0;
       Buf   :=   Source;
       i   :=   Pos(Sub,   Source);
       Len   :=   Length(Sub);
       while   i   <>   0   do
       begin
           inc(C);
           Inc(Result,   i);
           Delete(Buf,   1,   i   +   Len   -   1);
           i   :=   Pos(Sub,   Buf);
           if   C   >=   Index   then   Break;
           if   i   >   0   then   Inc(Result,   Len   -   1);
       end;
       if   C   <   Index   then   Result   :=   0;
    end;


    procedure TForm1.Button1Click(Sender: TObject);
    var
    t,y:integer;
    o,x,c:string;
    g,p,g1:integer;

    begin
    memo1.text:='';
     for p:=0 to 5 do
     BEGIN

    Randomize;
    t := random(20);
    while (t < 1) do
    t := random(20);

     label1.Caption:=inttostr(t);

                y:=t+1;

     c:='topfox000|topfox001|topfox002|topfox003|topfox004|topfox005|topfox006|topfox0007|topfox008|topfox009|tellyoumysecret000|tellyoumysecret002|tellyoumysecret003|tellyoumysecret004|tellyoumysecret005|tellyoumysecret006|'+
    'onhacker046|onionhacker047|onionhacker048|onionhacker049|onionhacker140|onionhacker141|onionhacker142|onionhacker143|onionhacker144';
     test.text:=test.text+#13#10+inttostr(PosEx( c, '|',t));//返回5
      g:= PosEx( c, '|',t);//返回5
    test.text:=test.text+#13#10+inttostr(PosEx( c, '|',y));//返回5
       g1:=PosEx( c, '|',y);//返回5
    x:=Copy(c,g,g1-g);

         memo1.text:=memo1.text  +x;
     END;

    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    memo1.Text:='';
    end;

    end.

  • 相关阅读:
    左偏树——可以标记合并的堆
    主席树——多棵线段树的集合
    [中山市选2011]完全平方数 ——莫比乌斯函数
    决策单调性优化dp
    [NOI2015]寿司晚宴——状压dp
    【[国家集训队]等差子序列】
    线性基——数集压缩自动机
    Java实现 蓝桥杯VIP 算法训练 筛选号码
    BSGS&EXBSGS 大手拉小手,大步小步走
    CRT&EXCRT 中国剩余定理及其扩展
  • 原文地址:https://www.cnblogs.com/onionhacker/p/3485192.html
Copyright © 2011-2022 走看看