[GAP Forum] How can I read integers from a file?

Stefan Kohl stefan at mcs.st-and.ac.uk
Mon Nov 14 21:10:45 GMT 2011


Dear Forum,

Lisette Brillemans wrote:

> I would like to read some integers from a text file into my program.
> So the file looks something like this:
>
> 34,56,12,8,75,4,23
>
> and I would like a program to read these integers into a file.
>
> I would like to know how to do this and many thanks in advance for any
> help.

This can be done as follows :

gap> numbers := List(SplitString(StringFile("C:/GAP/NUMBERS.TXT"),",","\r\n"),Int);
[ 34, 56, 12, 8, 75, 4, 23 ]

Of course "C:/GAP/NUMBERS.TXT" needs to be replaced by the path and name of your file.

Hope this helps,

    Stefan Kohl





More information about the Forum mailing list