Jump to content
Janilabo

AllBetween

Recommended Posts

Returns all strings between S1 and S2 of STR. Exaple included.

 

AllBetween

[scar]function AllBetween(s1, s2, str: string): TStringArray;

var

s1L, s2L, sL, r, sp, start, fp, finish: Integer;

tmp: string;

begin

sL := Length(str);

s1L := Length(s1);

s2L := Length(s2);

if (sL > 0) and (s1L > 0) and (s2L > 0) then

if (sL >= (s1L + s2L)) then

begin

SetLength(Result, (sL * (sL - (s1L + s2L))));

repeat

sp := PosEx(s1, str, (start + 1));

if (sp > 0) then

begin

start := sp;

finish := ((start + s1L) - 1);

repeat

fp := PosEx(s2, str, (finish + 1));

if fp > 0 then

begin

finish := fp;

tmp := Copy(str, (start + s1L), (finish - (start + s1L)));

if tmp <> '' then

begin

Result[r] := tmp;

Inc®;

tmp := '';

end;

end;

until (fp <= 0);

end;

until (sp <= 0);

end;

SetLength(Result, r);

end;

 

var

str: string;

TSA: TStringArray;

h, i: Integer;

 

begin

ClearDebug;

str := '***AllBetween()**Test***';

TSA := AllBetween('*', '*', str);

h := High(TSA);

if (h < 0) then

Exit;

for i := 0 to h do

WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA);

SetLength(TSA, 0);

end.[/scar]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...