截取指定符号之间的字符串(随机读取)delphi实例代码
<P><div class="codetitle"><span><U>复制代码</U></span> 代码如下:</div><div class="codebody" id="code17225"><BR>unit Unit1;</P><P>interface</P>
<P>uses<BR> Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,<BR> Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;</P>
<P>type<BR> TForm1 = class(TForm)<BR> test: TMemo;<BR> Button1: TButton;<BR> Memo1: TMemo;<BR> procedure Button1Click(Sender: TObject);<BR> private<BR> { Private declarations }<BR> public<BR> { Public declarations }<BR> end;</P>
<P>var<BR> Form1: TForm1;</P>
<P>implementation</P>
<P>{$R *.dfm}</P>
<P>function PosEx(const Source, Sub: string; Index: integer): integer;<BR>var<BR> Buf : string;<BR> i, Len, C : integer;<BR>begin<BR> C := 0;<BR> Result := 0;<BR> Buf := Source;<BR> i := Pos(Sub, Source);<BR> Len := Length(Sub);<BR> while i <> 0 do<BR> begin<BR> inc(C);<BR> Inc(Result, i);<BR> Delete(Buf, 1, i + Len - 1);<BR> i := Pos(Sub, Buf);<BR> if C >= Index then Break;<BR> if i > 0 then Inc(Result, Len - 1);<BR> end;<BR> if C < Index then Result := 0;<BR>end;</P>
<P><BR>procedure TForm1.Button1Click(Sender: TObject);<BR>var<BR>i,y:integer;<BR>x,c:string;<BR>g,g1:integer;<BR>begin<BR> randomize; //生成随机数种子<BR> i:=random(30);<BR> y:=i+1;</P>
<P> c:='topfox000|topfox001|topfox002|topfox003|topfox004|topfox005|topfox006|topfox0007|topfox008|topfox009|tellyoumysecret000|tellyoumysecret002|tellyoumysecret003|tellyoumysecret004|tellyoumysecret005|tellyoumysecret006|'+<BR>'onhacker046|onionhacker047|onionhacker048|onionhacker049|onionhacker140|onionhacker141|onionhacker142|onionhacker143|onionhacker144';<BR> test.text:=test.text+inttostr(PosEx( c, '|',i));//返回5<BR> g:= PosEx( c, '|',i)+1;//返回5<BR>test.text:=test.text+inttostr(PosEx( c, '|',y));//返回5<BR> g1:=PosEx( c, '|',y);//返回5<BR>x:=Copy(c,g,g1-g);<BR>memo1.text:=x;</P>
<P>end;</P>
<P>end.<BR></div></P>
<div class="art_xg">
<b>您可能感兴趣的文章:</b><ul><li>Delphi7中群发Email邮件的方法</li><li>delphi实现保存和读取图片的方法</li><li>Delphi远程连接Mysql的实现方法</li><li>Delphi创建开机启动项的方法示例</li><li>Delphi编程常用快捷键大全</li><li>Delphi实现获取句柄并发送消息的方法</li><li>Delphi实现木马文件传输代码实例</li><li>Delphi实现限定软件使用时间的方法</li><li>delphi字符串分隔函数用法实例</li></ul>
</div>
</div>
<!--endmain-->
頁:
[1]