Convert a file to a list or string in a schema

I have a problem with a text file and converting it to a list or string.

Say I have "blah.txt" which contains:

3 + 4

Now I want to name the file that, as I know, can be made

(define in (open-input-file "blah.txt"))

Where can I get it from here?

+5
source share
2 answers

Take a look at file->listor file->lineswhich should do what you want in Racket. That is, something like (file->lines "blah.txt")will give you a list of lines from a file. More generally, look at the I / O help entry .

+12
source

Given the file name, file-> string loads the file and returns the contents as a string.

+3
source

All Articles