截取指定符号之间的字符串(随机读取)delphi实例代码

所属分类: 软件编程 / Delphi 阅读数: 63
收藏 0 赞 0 分享

复制代码 代码如下:

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;
    procedure Button1Click(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
i,y:integer;
x,c:string;
g,g1:integer;
begin
 randomize;  //生成随机数种子
            i:=random(30);
            y:=i+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+inttostr(PosEx( c, '|',i));//返回5
  g:= PosEx( c, '|',i)+1;//返回5
test.text:=test.text+inttostr(PosEx( c, '|',y));//返回5
   g1:=PosEx( c, '|',y);//返回5
x:=Copy(c,g,g1-g);
memo1.text:=x;

end;

end.

更多精彩内容其他人还在看

delphi中exit,abort,break,continue的区别介绍

本文详细介绍下delphi中表示跳出的有break,continue, exit,abort, halt, runerror的区别,感兴趣的朋友可以参考下哈,希望对你学习跳出有所帮助
收藏 0 赞 0 分享

delphi设置开机自动启动函数具体实现

有些程序要设置为开机启动,所以自己写了个函数方便以后使用,实现比较简单,感兴趣的朋友可以参考下哈
收藏 0 赞 0 分享

delphi简单判断程序30秒没有键盘和鼠标动作示例

本文为大家详细介绍下delphi判断程序30秒没有键盘和鼠标动作,这里给timer设置了1000ms)的参数,表示30秒的间隔,具体实现如下,感兴趣的朋友可以参考下哈
收藏 0 赞 0 分享

delphi程序全屏显示无标题栏覆盖整个屏幕(适合屏保)

delphi 简单实现程序全屏显示无标题栏,覆盖整个屏幕,这个在做工控机或屏保时有用的,具体代码如下,感兴趣的朋友可以参考下哈
收藏 0 赞 0 分享

delphi发送消息控制滚动条使用示例

本文为大家详细介绍下delphi实现发送消息控制滚动条,主要函数及用法如下,感兴趣的朋友可以参考下哈
收藏 0 赞 0 分享

Delphi 生成excel中饼图的实例代码

这篇文章介绍了Delphi 生成excel中饼图的实例代码,有需要的朋友可以参考一下
收藏 0 赞 0 分享

Delphi实现树型结构具体实例

这篇文章介绍了Delphi实现树型结构具体实例,有需要的朋友可以参考一下
收藏 0 赞 0 分享

delphi mysql adbquery数据提供程序或其他服务返回 E_FAIL 状态

这篇文章主要介绍了delphi mysql adbquery数据提供程序或其他服务返回 E_FAIL 状态的解决方法
收藏 0 赞 0 分享

截取指定符号之间的字符串(随机读取)delphi实例代码

这篇文章主要介绍了截取指定符号之间的字符串(随机读取)delphi实例代码,有需要的朋友可以参考一下
收藏 0 赞 0 分享

Delphi中设置条件断点的方法讲解

这篇文章主要介绍了Delphi中设置条件断点的方法,有需要的朋友可以参考一下
收藏 0 赞 0 分享
查看更多