[fpc-pascal] splitting string into array
Daniël Mantione
daniel.mantione at freepascal.org
Tue Jul 10 13:22:22 CEST 2007
Op Tue, 10 Jul 2007, schreef Marc Santhoff:
> Hi,
>
> is there any function in the libraries of fpc for splitting a string
> into an array naming the separator?
>
> In awk for eample if you do this:
>
> split("ab-cd-ef", x, "-")
> print x[2]
>
> it would split up the first string using "-" as separator and print
>
> cd
>
> to the output. That's what I'm searching for.
> In pascal. ;)
In dynamically typed languages writing such a construction is very easy
because one can simply allocate an array at runtime of the needed type (if
there are multiple types at all).
In Pascal, being a statically typed language, the array element does
matter and cannot be decided about at runtime. Allocating an array at
runtime is possible to, but inefficient because the size isn't known in
advance, growing it one element at a time is a good way to fragment the
heap.
Daniël
More information about the fpc-pascal
mailing list