delphi 如何回圈獲取網頁原始碼中兩個字串之間的內容,并寫入陣列
function GetStr(Str,StrBegin,StrEnd,strxunhuan:string;Isxunhuan :Boolean = false):string;
str 全部文本
StrBegin :開始文本
StrEnd :結束文本
回傳 :開始文本和結束文本之間的文本內容
isxunhuan(陣列) : false(默認)的話不回圈獲取,true的話回圈獲取 (可不輸入)
自己寫了個不能回圈的,回圈的怎么寫呢?

begin
in_star:=AnsiPos(strbegin,Str)+length(strbegin);
in_end:=AnsiPos(strend,Str);
result:=copy(Str,in_star,in_end-in_star);
end
求大神幫忙寫個函式,感激不盡
uj5u.com熱心網友回復:
這類任務建議使用正則運算式來完成。uj5u.com熱心網友回復:
......type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Memo1: TMemo;
Memo2: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure StrSplite(AStr,ASBegin,ASEnd:string;AStrings:TStrings;AIsXunHun:Boolean=True);
var
iB,iE:Integer;
s:string;
begin
iB:=Pos(ASBegin,AStr);
if iB>0 then
begin
iE:=Pos(ASEnd,AStr);
if iE>0 then
begin
iB:=iB+length(ASBegin);
s:=Copy(AStr,iB,iE-iB);
AStrings.Add(s);
if AIsXunHun then
begin
AStr:=Copy(AStr,iE+length(ASEnd),length(AStr));
StrSplite(AStr,ASBegin,ASEnd,AStrings,AIsXunHun);
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo2.Clear;
StrSplite(Memo1.Text,edit1.Text,edit2.Text,Memo2.Lines,True);
end;
uj5u.com熱心網友回復:
你用正則好了,指定首尾字串,直接就給你回傳所有的結果了uj5u.com熱心網友回復:
我也有類似問題,請問解決了嗎,麻煩把正確的函式及用法貼出來一下,謝謝!轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/55150.html
標籤:語言基礎/算法/系統設計
