Janilabo

Janilabo | PosAll() [Simba]

Jun 20th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.85 KB | None | 0 0
  1. function PosAll(s, str: string): array of Integer;
  2. var
  3.   sL, strL, o, p, r: Integer;
  4. begin
  5.   sL := Length(s);
  6.   strL := Length(str);
  7.   if (sL > strL) then
  8.     Exit;
  9.   SetLength(Result, strL);
  10.   repeat
  11.     p := PosEx(s, str, (o + 1));
  12.     if (p > 0) then
  13.     begin
  14.       Result[r] := p;
  15.       o := p;
  16.       Inc(r);
  17.     end;
  18.   until (p <= 0);
  19.   SetLength(Result, r);
  20. end;
  21.  
  22. var
  23.   s, str: string;
  24.   TIA: array of Integer;
  25.   h, i: Integer;
  26.  
  27. begin
  28.   ClearDebug;
  29.   str := '|||| PosAll() Test ||| *** ||| Should work pretty well. ||||';
  30.   s := '||';
  31.   TIA := PosAll(s, str);
  32.   h := High(TIA);
  33.   if (h < 0) then
  34.     Exit;
  35.   str := '"' + s + '" positions in str: ';
  36.   for i := 0 to h do
  37.     if (i < h) then
  38.       str := str + IntToStr(TIA[i]) + ', '
  39.     else
  40.       str := str + IntToStr(TIA[i]) + '.';
  41.   WriteLn(str);
  42.   SetLength(TIA, 0);
  43. end.
Advertisement
Add Comment
Please, Sign In to add comment