Janilabo

Janilabo | AllBetween() [Simba]

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