Be seen. Boost your question’s priority for more expert views and faster solutions
function explode(const separator, s: string; limit: Integer = 0): TDynStringArray;
var SepLen: Integer;
F, P: PChar;
begin
SetLength(Result, 0);
if (S = '') or (Limit < 0) then
Exit;
if Separator = '' then
begin
SetLength(Result, 1);
Result[0] := S;
Exit;
end;
SepLen := Length(Separator);
From: http://www.delphi3000.com/articles/article_3609.asp (see comments on delphi3000 page)
unction Explode(const Separator, S: String; Limit: Integer = 0): TDynStringArray;
var
SepLen: Integer;
F, P: PChar;
begin
SetLength(Result, 0);
if (S = '') or (Limit < 0) then
Exit;
if Separator = '' then
begin
SetLength(Result, 1);
Result[0] := S;
Exit;
end;
SepLen := Length(Separator);
P := PChar(S);
while P^ <> #0 do
begin
F := P;
P := AnsiStrPos(P, PChar(Separator));
if (P = nil) or ((Limit > 0) and (Length(Result) = Limit - 1)) then
P := StrEnd(F);
SetLength(Result, Length(Result) + 1);
SetString(Result[High(Result)], F, P - F);
F := P;
//ERROR in case if string is finished with separator
if P = Separator then
SetLength(Result, Length(Result) + 1);
//END of modification
while (P^ <> #0) and (P - F < SepLen) do
Inc(P);
end;
end;
List := TStringList.Create;
try
List.StrictDelimiter := true;
List.Delimiter := Separator;
List.DelimitedText := s;
for I := 0 to List.Count-1 do
ShowMessage(List[I]); // like this you have access to the elements
finally
List.Free;
end;
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
try
List.Delimiter := Separator;
List.DelimitedText := s;
for I := 0 to List.Count-1 do
ShowMessage(List[I]); // like this you have access to the elements
finally
List.Free;
end;