Home > Back-end >  How Delphi cycle in source code for the page content between two strings
How Delphi cycle in source code for the page content between two strings

Time:09-19

How Delphi cycle for web content between two strings in the source code, and write array
The function GetStr (Str, StrBegin StrEnd, strxunhuan: string; Isxunhuan: Boolean=false) : string;
All text STR
StrBegin: start text
StrEnd: the end of the text
Returns: start the text between the end of text and text content
Isxunhuan (array) : false (default) if not loop gain, loop gain true words (not input)

Himself wrote a cannot cycle, cycle of how to write?
The begin
In_star:=AnsiPos (strbegin, Str) + length (strbegin);
In_end:=AnsiPos (strend, Str);
Result:=copy (Str, in_star in_end - in_star);
End

beg god to help write a function, grateful

CodePudding user response:

Suggest to use regular expressions to complete such tasks,

CodePudding user response:

.
Type
TForm1=class (TForm)
Edit1: TEdit;
Edit2: TEdit;
Memo1: TMemo;
Memo2: TMemo;
For: TButton;
Procedure Button1Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form1: TForm1;

Implementation

{$R *. DFM}

Procedure StrSplite (AStr ASBegin, overall: string; AStrings: TStrings; AIsXunHun: Boolean=True);
Var
The iB, iE: Integer;
S: a string;
The begin
IB:=Pos (ASBegin AStr);
If iB> 0 then
The begin
IE:=Pos (overall, AStr);
If iE> 0 then
The begin
The iB:=iB + length (ASBegin);
S:=Copy (AStr, iB, iE - iB);
AStrings. Add (s);
If AIsXunHun then
The begin
AStr:=Copy (AStr, iE + length (overall), length (AStr));
StrSplite (AStr ASBegin, overall, AStrings AIsXunHun);
end;
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
The begin
Memo2. The Clear;
StrSplite (Memo1. Text, edit1. Text, edit2. Text, Memo2. Lines, True);
end;

CodePudding user response:

You with regular, fore and aft specified string, will give you back all the results directly

CodePudding user response:

I also have a similar problem, is solved, please, bother the correct function and usage posted, thank you!
  • Related