Janilabo

explode2

Aug 4th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.27 KB | None | 0 0
  1. function Explode2(separator, str: string): TStringArray;
  2. var
  3.   a, b, l, p, r, s: Integer;
  4.   m: Boolean;
  5. begin;
  6.   SetLength(Result, 1);
  7.   l := Length(str);
  8.   if (l > 0) then
  9.   begin
  10.     s := Length(separator);
  11.     a := 1;
  12.     p := 1;
  13.     r := 0;
  14.     while ((a + (s - 1)) <= l) do
  15.     begin
  16.       for b := 1 to s do
  17.       begin
  18.         m := (str[((a + b) - 1)] = separator[b]);
  19.         if not m then
  20.           Break;
  21.       end;
  22.       if m then
  23.       begin
  24.         Result[r] := Copy(str, p, (a - p));
  25.         p := (a + s);
  26.         a := ((a + s) - 1);
  27.         if (a = l) then
  28.           Exit;
  29.         Inc(r);
  30.         SetLength(result, (r + 1));
  31.       end;
  32.       Inc(a);
  33.     end;
  34.     Result[r] := Copy(str, p, ((l - p) + 1));
  35.   end else
  36.     Result[0] := '';
  37. end;
  38.  
  39. var
  40.   s: string;
  41.   x: Integer;
  42.   a, b: TStringArray;
  43.  
  44. begin
  45.   ClearDebug;
  46.   x := OpenFile(ScriptPath + 'ClearTPAFromTPA2.simba', False);
  47.   ReadFileString(x, s, FileSize(x));
  48.   CloseFile(x);
  49.   s := (s + '  !   a');
  50.   a := Explode('  ', s);
  51.   WriteLn(ToStr(a[High(a)]));
  52.   WriteLn(ToStr(Length(a)));
  53.   b := Explode2('  ', s);
  54.   WriteLn(ToStr(b[High(b)]));
  55.   WriteLn(ToStr(Length(b)));
  56.   if (ToStr(a) = ToStr(b)) then
  57.     WriteLn('MATCH!');
  58.   SetLength(a, 0);
  59.   SetLength(b, 0);
  60. end.
Advertisement
Add Comment
Please, Sign In to add comment