Janilabo

Janilabo | AllBetween2() [Simba]

Jun 20th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.31 KB | None | 0 0
  1. function AllBetween2(s1, s2, str: string): array of string;
  2. var
  3.   s1L, s2L, sL, r, sp, start, fp, finish: Integer;
  4.   tmp: string;
  5. begin
  6.   sL := Length(str);
  7.   s1L := Length(s1);
  8.   s2L := Length(s2);
  9.   if (sL > 0) and (s1L > 0) and (s2L > 0) then
  10.     if (sL >= (s1L + s2L)) then
  11.     begin
  12.       SetLength(Result, (sL * (sL - (s1L + s2L))));
  13.       repeat
  14.         sp := PosEx(s1, str, (start + 1));
  15.         if (sp > 0) then
  16.         begin
  17.           start := sp;
  18.           finish := ((start + s1L) - 1);
  19.           repeat
  20.             fp := PosEx(s2, str, (finish + 1));
  21.             if fp > 0 then
  22.             begin
  23.               finish := fp;
  24.               tmp := Copy(str, (start + s1L), (finish - (start + s1L)));
  25.               if tmp <> '' then
  26.               begin
  27.                 Result[r] := tmp;
  28.                 Inc(r);
  29.                 tmp := '';
  30.               end;
  31.             end;
  32.           until (fp <= 0);
  33.         end;
  34.       until (sp <= 0);
  35.     end;
  36.   SetLength(Result, r);
  37. end;
  38.  
  39. var
  40.   str: string;
  41.   TSA: array of string;
  42.   h, i: Integer;
  43.  
  44. begin
  45.   ClearDebug;
  46.   str := '***AllBetween2()**Test***';
  47.   TSA := AllBetween2('*', '*', str);
  48.   h := High(TSA);
  49.   if (h < 0) then
  50.     Exit;
  51.   for i := 0 to h do
  52.     WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA[i]);
  53.   SetLength(TSA, 0);
  54. end.
Advertisement
Add Comment
Please, Sign In to add comment