Janilabo

explode2

Dec 2nd, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.91 KB | None | 0 0
  1. function StrExplode(d: Char; str: string): TStringArray;
  2. var
  3.   i, l, r, q: 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.     for i := 1 to l do
  12.       if (str[i] = d) then
  13.       begin
  14.         r := (r + 1);
  15.         if (q <= r) then
  16.         begin
  17.           q := (q + q);
  18.           SetLength(Result, q);
  19.         end;
  20.       end else
  21.         Result[r] := (Result[r] + str[i]);
  22.     SetLength(Result, (r + 1));
  23.   end else
  24.     Result[0] := str;
  25. end;
  26.  
  27. function StrExplode2(d: Char; str: string): TStringArray;
  28. var
  29.   i, l, r: Integer;
  30. begin
  31.   SetLength(Result, 1);
  32.   l := Length(str);
  33.   if (l > 0) then
  34.   begin
  35.     r := 0;
  36.     for i := 1 to l do
  37.       if (str[i] = d) then
  38.       begin
  39.         r := (r + 1);
  40.         SetLength(Result, (r + 1));
  41.       end else
  42.         Result[r] := (Result[r] + str[i]);
  43.   end else
  44.     Result[0] := str;
  45. end;
Advertisement
Add Comment
Please, Sign In to add comment