takafunkcja1 | takafunkcja2 | inne rzeczy
Type TParams = Array Of String;
Function GetParams(Par: String; Sep: Char): TParams;
Var I : Integer;
P : Integer;
Str: String;
Begin
SetLength(Result, 0);
if (Trim(Par) = '') Then
Exit;
SetLength(Result, 1);
Str := Par;
I := 0;
Delete(Str, Pos(Sep, Str), Length(Str));
Result[0] := Trim(Str);
While (Pos(Sep, Par) > 0) Do
Begin
Inc(I);
SetLength(Result, I+1);
P := Pos(Sep, Par);
Str := Par;
Delete(Str, 1, P);
Delete(Str, Pos(Sep, Str), Length(Str));
Delete(Par, 1, P);
Result[I] := Trim(Str);
End;
End;
Fragment kodu mojego starego parsera (jak chcesz, to mogę wysłać Ci kod - 2773 linie :]).
Przykładowy kod:
{$APPTYPE CONSOLE}
Program Test;
Type TParams = Array Of String;
Function GetParams(Par: String; Sep: Char): TParams;
Var I : Integer;
P : Integer;
Str: String;
Begin
SetLength(Result, 0);
if (Trim(Par) = '') Then
Exit;
SetLength(Result, 1);
Str := Par;
I := 0;
Delete(Str, Pos(Sep, Str), Length(Str));
Result[0] := Trim(Str);
While (Pos(Sep, Par) > 0) Do
Begin
Inc(I);
SetLength(Result, I+1);
P := Pos(Sep, Par);
Str := Par;
Delete(Str, 1, P);
Delete(Str, Pos(Sep, Str), Length(Str));
Delete(Par, 1, P);
Result[I] := Trim(Str);
End;
End;
Var Res: TParams;
I: Integer;
Begin
Res := GetParams('Hello|World|!', '|');
For I := 0 To High(Res) Do
WriteLn(Res[I]);
(* Wyświetli:
Hello
World
!
*)
ReadLn;
End.
:)