截取指定符號(hào)之間的字符串(隨機(jī)讀取)delphi實(shí)例代碼
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; //生成隨機(jī)數(shù)種子
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.
相關(guān)文章
delphi mysql adbquery數(shù)據(jù)提供程序或其他服務(wù)返回 E_FAIL 狀態(tài)
這篇文章主要介紹了delphi mysql adbquery數(shù)據(jù)提供程序或其他服務(wù)返回 E_FAIL 狀態(tài)的解決方法2013-11-11
Delphi隱藏TPageControl的標(biāo)簽實(shí)例介紹
件是一組頁(yè)面集,用于構(gòu)造一個(gè)多頁(yè)對(duì)話框,它顯示多個(gè)交互頁(yè)(TTabSheet 對(duì)象),接下來(lái)為大家介紹下Delphi隱藏TPageControl的標(biāo)簽方法2013-04-04
Delphi實(shí)現(xiàn)Listbox中的item根據(jù)內(nèi)容顯示不同顏色的方法
這篇文章主要介紹了Delphi實(shí)現(xiàn)Listbox中的item根據(jù)內(nèi)容顯示不同顏色的方法,需要的朋友可以參考下2014-07-07
delphi設(shè)置開機(jī)自動(dòng)啟動(dòng)函數(shù)具體實(shí)現(xiàn)
有些程序要設(shè)置為開機(jī)啟動(dòng),所以自己寫了個(gè)函數(shù)方便以后使用,實(shí)現(xiàn)比較簡(jiǎn)單,感興趣的朋友可以參考下哈2013-06-06
Delphi2007編譯的程序在Win7下圖標(biāo)模糊的解決辦法
這篇文章主要介紹了Delphi2007編譯的程序在Win7下圖標(biāo)模糊的解決辦法,需要的朋友可以參考下2014-08-08

