[fpc-pascal] Parsing parameters inside an interpreter
Ludo Brands
ludo.brands at free.fr
Mon May 14 11:33:35 CEST 2012
>
> I trying to build a very small interpreter. I can type commands like:
>
> $ add "Luciano de Souza" luchyanus at gmail.com
>
> Somewhere in my code, I can have something like:
>
> procedure parse(commandline: string; var params: array of string);
>
> In this case, the commandline has the format: "add %s %s". So
> I would obtain:
>
> parse('add "Luciano de Souza" luchyanus at gmail.com', params);
>
> After this command, the parameter would have the following values:
>
> params[0] := 'add';
> params[1] := 'Luciano de Souza';
> params[2] := 'luchyanus at gmail.com';
>
> My question is: there is a way to do it easily using a
> standard class of Freepascal?
>
Use TSTringList.DelimitedText:
params.Delimiter:=' ';
params.StrictDelimiter:=false;
params.QuoteChar:='"';
params.DelimitedText:='add "Luciano de Souza" luchyanus at gmail.com';
results in
params[0] := 'add';
params[1] := 'Luciano de Souza';
params[2] := 'luchyanus at gmail.com';
Ludo
More information about the fpc-pascal
mailing list