Advertisement
HwapX

SplitStr Pascal

Mar 4th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.60 KB | None | 0 0
  1. uses Types;
  2.  
  3. function SplitStr(const Str: string; const Delimiter: string): TStringDynArray;
  4. var
  5.   L : Integer;
  6.   I : Integer;
  7.   S : Integer;
  8.   D : Integer;
  9.   A : Integer;
  10. begin
  11.   L := Length(Str);
  12.   S := 1;
  13.   D := Length(Delimiter);
  14.   I := 1;
  15.   while I <= L do
  16.   begin
  17.     if Copy(Str, I, D) = delimiter then
  18.     begin
  19.       A := Length(Result);
  20.       SetLength(Result, A + 1);
  21.       Result[A] := Copy(Str, S, I - S);
  22.       S := I + D;
  23.       Inc(I, D);
  24.     end
  25.     else
  26.       Inc(I);
  27.   end;
  28.    
  29.   A := Length(Result);
  30.   SetLength(Result, A + 1);
  31.   Result[A] := Copy(Str, S, L-S);
  32. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement