Vlastimil Burian
2015-02-19 12:34:52 UTC
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.
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.