Jump to content
Janilabo

PosAll

Recommended Posts

Returns all positions of S in STR. Example included.

 

PosAll

[scar]function PosAll(s, str: string): TIntArray;

var

sL, strL, o, p, r: Integer;

begin

sL := Length(s);

strL := Length(str);

if (sL > strL) then

Exit;

SetLength(Result, strL);

repeat

p := PosEx(s, str, (o + 1));

if (p > 0) then

begin

Result[r] := p;

o := p;

Inc®;

end;

until (p <= 0);

SetLength(Result, r);

end;

 

var

s, str: string;

TIA: TIntArray;

h, i: Integer;

 

begin

ClearDebug;

str := '|||| PosAll() Test ||| *** ||| Should work pretty well. ||||';

s := '||';

TIA := PosAll(s, str);

h := High(TIA);

if (h < 0) then

Exit;

str := '"' + s + '" positions in str: ';

for i := 0 to h do

if (i < h) then

str := str + IntToStr(TIA) + ', '

else

str := str + IntToStr(TIA) + '.';

WriteLn(str);

SetLength(TIA, 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...