Advertisement
Janilabo

explode3

Dec 2nd, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.36 KB | None | 0 0
  1. function StrExplode(d: Char; str: string): TStringArray;
  2. var
  3.   i, l, r, q, c, s: Integer;
  4. begin
  5.   SetLength(Result, 1);
  6.   l := Length(str);
  7.   if (l > 0) then
  8.   begin
  9.     r := 0;
  10.     q := 1;
  11.     i := 0;
  12.     s := 1;
  13.     c := 0;
  14.     repeat
  15.       i := (i + 1);
  16.       if (str[i] = d) then
  17.       begin
  18.         if (c > 0) then
  19.           Result[r] := Copy(str, s, (c + 1));
  20.         r := (r + 1);
  21.         if (q <= r) then
  22.         begin
  23.           q := (q + q);
  24.           SetLength(Result, q);
  25.         end;
  26.         s := (i + 1);
  27.         c := 0;
  28.       end else
  29.         c := (c + 1);
  30.     until (i = l);
  31.     if (c > 0) then
  32.       Result[r] := Copy(str, s, (c + 1));
  33.     SetLength(Result, (r + 1));
  34.   end else
  35.     Result[0] := str;
  36. end;
  37.  
  38. function StrExplode2(d: Char; str: string): TStringArray;
  39. var
  40.   i, l, r, c, s: Integer;
  41. begin
  42.   SetLength(Result, 1);
  43.   l := Length(str);
  44.   if (l > 0) then
  45.   begin
  46.     r := 0;
  47.     i := 0;
  48.     s := 1;
  49.     c := 0;
  50.     repeat
  51.       i := (i + 1);
  52.       if (str[i] = d) then
  53.       begin
  54.         if (c > 0) then
  55.           Result[r] := Copy(str, s, (c + 1));
  56.         r := (r + 1);
  57.         SetLength(Result, (r + 1));
  58.         s := (i + 1);
  59.         c := 0;
  60.       end else
  61.         c := (c + 1);
  62.     until (i = l);
  63.     if (c > 0) then
  64.       Result[r] := Copy(str, s, (c + 1));
  65.   end else
  66.     Result[0] := str;
  67. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement