Explode function not working properly

6 views
Skip to first unread message

Vlastimil Burian

unread,
Feb 19, 2015, 7:34:53 AM2/19/15
to
type
TDynamicStringArray = array of string;


function Explode(const Separator: string; S: string): TDynamicStringArray;

var
I, SepPos, SepLen: Integer;

begin
if not (Separator <> '')
then raise EInvalidInputStringFunctions.Create('Explode');

I := 0;
SetLength(Result, 1);

SepLen := Length(Separator);
SepPos := Pos(Separator, S);
while SepPos > 0 do begin
Result[I] := Copy(S, 1, SepPos - 1);
Delete(S, 1, SepPos + SepLen - 1);
SepPos := Pos(Separator, S);
Inc(I);
SetLength(Result, I + 1);
end;

Result[I] := S;
end;


What is wrong? Please help.

Vlastimil Burian

unread,
Feb 20, 2015, 4:26:46 AM2/20/15
to
Fixed.
Reply all
Reply to author
Forward
0 new messages