[fpc-pascal] How to split file of whitespace separated numbers?

Bo Berglund bo.berglund at gmail.com
Fri Dec 23 10:42:05 CET 2016

On Fri, 23 Dec 2016 10:04:09 +0100, Gabor Boros
<gaborboros at yahoo.com> wrote:

>2016. 12. 23. 9:14 keltezéssel, Bo Berglund írta:
>> Is there a quick way to split a string of whitespace separated values
>> into the separate members?

>   SL.DelimitedText:='   0.000    0.000    7.000    0.000  29.6628';

I did not know that one could do this and get away with it. Believed
one had to set the delimiter first and since it is varying number of
spaces it would not work.
But it seems like it does work!

I applied your method by removing all the code for handling this and
used only the following:
   ReadLn(F, sLine);
   slDecode.DelimitedText := sLine;


I timed my original code for a file of some 660000+ lines to 9.9s.
Original code takes 9.9 s to process the file.
Modified code takes 4.4 s

And I checked with the file containing the extra spaces and varying
size of whitespace. It too was processed correctly.

Thanks again!

Bo Berglund
Developer in Sweden

More information about the fpc-pascal mailing list